Use bundle mock for cluster test

Added a mock bundle to the command_test.go so as to avoid using the
testdata files for making a fake bundle. These files were still kept
since status_test.go requires them for testing.

Change-Id: Ia401a0a9f5db2d56ea501e04230dddf3f5e1639e
This commit is contained in:
Herrera, Josh (jh813b) 2021-08-23 12:01:12 -07:00 committed by Josh Herrera
parent fc20c79e47
commit 1b72fe8fda

View File

@ -26,10 +26,39 @@ import (
"opendev.org/airship/airshipctl/pkg/cluster"
"opendev.org/airship/airshipctl/pkg/document"
"opendev.org/airship/airshipctl/pkg/k8s/client/fake"
testdoc "opendev.org/airship/airshipctl/testutil/document"
)
type mockStatusOptions struct{}
func getAllDocCfgs() []string {
return []string{
`apiVersion: "example.com/v1"
kind: Resource
metadata:
name: stable-resource
namespace: target-infra
`,
}
}
func testFakeDocBundle() document.Bundle {
bundle := &testdoc.MockBundle{}
docCfgs := getAllDocCfgs()
allDocs := make([]document.Document, len(docCfgs))
for i, cfg := range docCfgs {
doc, err := document.NewDocumentFromBytes([]byte(cfg))
if err != nil {
return bundle
}
allDocs[i] = doc
}
bundle.On("GetAllDocuments").Return(allDocs, nil)
return bundle
}
func (o mockStatusOptions) GetStatusMapDocs() (*cluster.StatusMap, []document.Document, error) {
fakeClient := fake.NewClient(
fake.WithCRDs(makeResourceCRD(annotationValidStatusCheck())),
@ -38,11 +67,8 @@ func (o mockStatusOptions) GetStatusMapDocs() (*cluster.StatusMap, []document.Do
if err != nil {
return nil, nil, err
}
fakeDocBundle, err := document.NewBundleByPath("testdata/statusmap")
if err != nil {
return nil, nil, err
}
fakeDocBundle := testFakeDocBundle()
fakeDocs, err := fakeDocBundle.GetAllDocuments()
if err != nil {
return nil, nil, err