Move MockDocument implementation to testutils

Currently MockDocument implementation located under pkg/bootstrap/isogen
package, which is not relevant for it and makes it impossible to import
in other test packages. Also _test.go filename is not proper one for
this source file since it doesn't contain any unit tests inside.

Change-Id: I9b3f28df653637701f5d6fca4376da5a22f39658
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
Relates-To: #432
This commit is contained in:
Ruslan Aliev 2020-12-08 20:59:45 -06:00
parent d7ca864295
commit 94a17694ea
3 changed files with 30 additions and 5 deletions

View File

@ -31,6 +31,7 @@ import (
"opendev.org/airship/airshipctl/pkg/log" "opendev.org/airship/airshipctl/pkg/log"
"opendev.org/airship/airshipctl/testutil" "opendev.org/airship/airshipctl/testutil"
testcontainer "opendev.org/airship/airshipctl/testutil/container" testcontainer "opendev.org/airship/airshipctl/testutil/container"
testdoc "opendev.org/airship/airshipctl/testutil/document"
) )
const testID = "TESTID" const testID = "TESTID"
@ -54,7 +55,7 @@ func TestBootstrapIso(t *testing.T) {
NetworkConfigFileName: "net-conf", NetworkConfigFileName: "net-conf",
}, },
} }
testDoc := &MockDocument{ testDoc := &testdoc.MockDocument{
MockAsYAML: func() ([]byte, error) { return []byte("TESTDOC"), nil }, MockAsYAML: func() ([]byte, error) { return []byte("TESTDOC"), nil },
} }
testBuilder := &testcontainer.MockContainer{ testBuilder := &testcontainer.MockContainer{
@ -74,7 +75,7 @@ func TestBootstrapIso(t *testing.T) {
tests := []struct { tests := []struct {
builder *testcontainer.MockContainer builder *testcontainer.MockContainer
cfg *api.ImageConfiguration cfg *api.ImageConfiguration
doc *MockDocument doc *testdoc.MockDocument
debug bool debug bool
expectedOut []string expectedOut []string
expectedErr error expectedErr error
@ -121,7 +122,7 @@ func TestBootstrapIso(t *testing.T) {
{ {
builder: testBuilder, builder: testBuilder,
cfg: testCfg, cfg: testCfg,
doc: &MockDocument{ doc: &testdoc.MockDocument{
MockAsYAML: func() ([]byte, error) { return nil, testErr }, MockAsYAML: func() ([]byte, error) { return nil, testErr },
}, },
debug: false, debug: false,

View File

@ -30,6 +30,7 @@ import (
"opendev.org/airship/airshipctl/pkg/phase/ifc" "opendev.org/airship/airshipctl/pkg/phase/ifc"
"opendev.org/airship/airshipctl/testutil" "opendev.org/airship/airshipctl/testutil"
testcontainer "opendev.org/airship/airshipctl/testutil/container" testcontainer "opendev.org/airship/airshipctl/testutil/container"
testdoc "opendev.org/airship/airshipctl/testutil/document"
) )
var ( var (
@ -93,7 +94,7 @@ func TestExecutorRun(t *testing.T) {
NetworkConfigFileName: "net-conf", NetworkConfigFileName: "net-conf",
}, },
} }
testDoc := &MockDocument{ testDoc := &testdoc.MockDocument{
MockAsYAML: func() ([]byte, error) { return []byte("TESTDOC"), nil }, MockAsYAML: func() ([]byte, error) { return []byte("TESTDOC"), nil },
} }

View File

@ -12,12 +12,13 @@
limitations under the License. limitations under the License.
*/ */
package isogen package document
import ( import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
) )
// MockDocument implements Document for unit test purposes
type MockDocument struct { type MockDocument struct {
MockAnnotate func() MockAnnotate func()
MockAsYAML func() ([]byte, error) MockAsYAML func() ([]byte, error)
@ -43,90 +44,112 @@ type MockDocument struct {
MockGetFieldValue func() (interface{}, error) MockGetFieldValue func() (interface{}, error)
} }
// Annotate Document interface implementation for unit test purposes
func (md *MockDocument) Annotate(_ map[string]string) { func (md *MockDocument) Annotate(_ map[string]string) {
md.MockAnnotate() md.MockAnnotate()
} }
// AsYAML Document interface implementation for unit test purposes
func (md *MockDocument) AsYAML() ([]byte, error) { func (md *MockDocument) AsYAML() ([]byte, error) {
return md.MockAsYAML() return md.MockAsYAML()
} }
// GetAnnotations Document interface implementation for unit test purposes
func (md *MockDocument) GetAnnotations() map[string]string { func (md *MockDocument) GetAnnotations() map[string]string {
return md.MockGetAnnotations() return md.MockGetAnnotations()
} }
// GetBool Document interface implementation for unit test purposes
func (md *MockDocument) GetBool(_ string) (bool, error) { func (md *MockDocument) GetBool(_ string) (bool, error) {
return md.MockGetBool() return md.MockGetBool()
} }
// GetFloat64 Document interface implementation for unit test purposes
func (md *MockDocument) GetFloat64(_ string) (float64, error) { func (md *MockDocument) GetFloat64(_ string) (float64, error) {
return md.MockGetFloat64() return md.MockGetFloat64()
} }
// GetFieldValue Document interface implementation for unit test purposes
func (md *MockDocument) GetFieldValue(_ string) (interface{}, error) { func (md *MockDocument) GetFieldValue(_ string) (interface{}, error) {
return md.MockGetFieldValue() return md.MockGetFieldValue()
} }
// GetGroup Document interface implementation for unit test purposes
func (md *MockDocument) GetGroup() string { func (md *MockDocument) GetGroup() string {
return md.MockGetGroup() return md.MockGetGroup()
} }
// GetInt64 Document interface implementation for unit test purposes
func (md *MockDocument) GetInt64(_ string) (int64, error) { func (md *MockDocument) GetInt64(_ string) (int64, error) {
return md.MockGetInt64() return md.MockGetInt64()
} }
// GetKind Document interface implementation for unit test purposes
func (md *MockDocument) GetKind() string { func (md *MockDocument) GetKind() string {
return md.MockGetKind() return md.MockGetKind()
} }
// GetLabels Document interface implementation for unit test purposes
func (md *MockDocument) GetLabels() map[string]string { func (md *MockDocument) GetLabels() map[string]string {
return md.MockGetLabels() return md.MockGetLabels()
} }
// GetMap Document interface implementation for unit test purposes
func (md *MockDocument) GetMap(_ string) (map[string]interface{}, error) { func (md *MockDocument) GetMap(_ string) (map[string]interface{}, error) {
return md.MockGetMap() return md.MockGetMap()
} }
// GetName Document interface implementation for unit test purposes
func (md *MockDocument) GetName() string { func (md *MockDocument) GetName() string {
return md.MockGetName() return md.MockGetName()
} }
// GetNamespace Document interface implementation for unit test purposes
func (md *MockDocument) GetNamespace() string { func (md *MockDocument) GetNamespace() string {
return md.MockGetNamespace() return md.MockGetNamespace()
} }
// GetSlice Document interface implementation for unit test purposes
func (md *MockDocument) GetSlice(_ string) ([]interface{}, error) { func (md *MockDocument) GetSlice(_ string) ([]interface{}, error) {
return md.MockGetSlice() return md.MockGetSlice()
} }
// GetString Document interface implementation for unit test purposes
func (md *MockDocument) GetString(_ string) (string, error) { func (md *MockDocument) GetString(_ string) (string, error) {
return md.MockGetString() return md.MockGetString()
} }
// GetStringMap Document interface implementation for unit test purposes
func (md *MockDocument) GetStringMap(_ string) (map[string]string, error) { func (md *MockDocument) GetStringMap(_ string) (map[string]string, error) {
return md.MockGetStringMap() return md.MockGetStringMap()
} }
// GetStringSlice Document interface implementation for unit test purposes
func (md *MockDocument) GetStringSlice(_ string) ([]string, error) { func (md *MockDocument) GetStringSlice(_ string) ([]string, error) {
return md.MockGetStringSlice() return md.MockGetStringSlice()
} }
// GetVersion Document interface implementation for unit test purposes
func (md *MockDocument) GetVersion() string { func (md *MockDocument) GetVersion() string {
return md.MockGetVersion() return md.MockGetVersion()
} }
// Label Document interface implementation for unit test purposes
func (md *MockDocument) Label(_ map[string]string) { func (md *MockDocument) Label(_ map[string]string) {
md.MockLabel() md.MockLabel()
} }
// MarshalJSON Document interface implementation for unit test purposes
func (md *MockDocument) MarshalJSON() ([]byte, error) { func (md *MockDocument) MarshalJSON() ([]byte, error) {
return md.MockMarshalJSON() return md.MockMarshalJSON()
} }
// ToObject Document interface implementation for unit test purposes
func (md *MockDocument) ToObject(_ interface{}) error { func (md *MockDocument) ToObject(_ interface{}) error {
return md.MockToObject() return md.MockToObject()
} }
// ToAPIObject Document interface implementation for unit test purposes
func (md *MockDocument) ToAPIObject(obj runtime.Object, scheme *runtime.Scheme) error { func (md *MockDocument) ToAPIObject(obj runtime.Object, scheme *runtime.Scheme) error {
return md.MockToAPIObject() return md.MockToAPIObject()
} }