From 1b72fe8fda28c348d3b5f634ec4524e7471fe425 Mon Sep 17 00:00:00 2001 From: "Herrera, Josh (jh813b)" Date: Mon, 23 Aug 2021 12:01:12 -0700 Subject: [PATCH] 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 --- pkg/cluster/command_test.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/pkg/cluster/command_test.go b/pkg/cluster/command_test.go index 60e0baa7e..998e6af32 100755 --- a/pkg/cluster/command_test.go +++ b/pkg/cluster/command_test.go @@ -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