Merge "Use bundle mock for cluster test"

This commit is contained in:
Zuul 2021-09-27 18:50:34 +00:00 committed by Gerrit Code Review
commit f9ee918eb6

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