From 300486482c82c25adc65fd2a43f948c7e0d0dfe4 Mon Sep 17 00:00:00 2001 From: Kostiantyn Kalynovskyi Date: Tue, 22 Sep 2020 14:15:12 -0500 Subject: [PATCH] Add test to phase bundleFactory The test makes sure that correct error is returned when bundle factory fails, and increases test coverage of executor() function Change-Id: Ibfc5d8ea1941a5d4d304a8afaedc5c89efe7c398 --- pkg/phase/client_test.go | 41 +++++++++++++++++++ pkg/phase/helper_test.go | 2 +- .../valid_site/phases/kustomization.yaml | 1 + .../phases/phase_no_docentrypoint.yaml | 9 ++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 pkg/phase/testdata/valid_site/phases/phase_no_docentrypoint.yaml diff --git a/pkg/phase/client_test.go b/pkg/phase/client_test.go index 6d0ec41b9..1253dea1c 100644 --- a/pkg/phase/client_test.go +++ b/pkg/phase/client_test.go @@ -206,6 +206,47 @@ func TestDocumentRoot(t *testing.T) { } } +func TestBundleFactoryExecutor(t *testing.T) { + cfg := testConfig(t) + + helper, err := phase.NewHelper(cfg) + require.NoError(t, err) + require.NotNil(t, helper) + + fakeRegistry := func() map[schema.GroupVersionKind]ifc.ExecutorFactory { + validBundleFactory := schema.GroupVersionKind{ + Group: "airshipit.org", + Version: "v1alpha1", + Kind: "Clusterctl", + } + invalidBundleFactory := schema.GroupVersionKind{ + Group: "airshipit.org", + Version: "v1alpha1", + Kind: "SomeExecutor", + } + bundleCheckFunc := func(config ifc.ExecutorConfig) (ifc.Executor, error) { + _, bundleErr := config.BundleFactory() + return nil, bundleErr + } + return map[schema.GroupVersionKind]ifc.ExecutorFactory{ + // validBundleFactory has DocumentEntryPoint defined + validBundleFactory: bundleCheckFunc, + // invalidBundleFactory does not have DocumentEntryPoint defined, error should be returned + invalidBundleFactory: bundleCheckFunc, + } + } + c := phase.NewClient(helper, phase.InjectRegistry(fakeRegistry)) + p, err := c.PhaseByID(ifc.ID{Name: "capi_init"}) + require.NoError(t, err) + _, err = p.Executor() + assert.NoError(t, err) + p, err = c.PhaseByID(ifc.ID{Name: "no_entry_point"}) + require.NoError(t, err) + _, err = p.Executor() + assert.Error(t, err) + assert.Equal(t, phase.ErrDocumentEntrypointNotDefined{PhaseName: "no_entry_point"}, err) +} + func fakeExecFactory(config ifc.ExecutorConfig) (ifc.Executor, error) { return fakeExecutor{}, nil } diff --git a/pkg/phase/helper_test.go b/pkg/phase/helper_test.go index f1a3fb0f2..68026310c 100644 --- a/pkg/phase/helper_test.go +++ b/pkg/phase/helper_test.go @@ -194,7 +194,7 @@ func TestHelperListPhases(t *testing.T) { }{ { name: "Success phase list", - phaseLen: 2, + phaseLen: 3, config: testConfig, }, { diff --git a/pkg/phase/testdata/valid_site/phases/kustomization.yaml b/pkg/phase/testdata/valid_site/phases/kustomization.yaml index fe91297a3..977c07f9d 100644 --- a/pkg/phase/testdata/valid_site/phases/kustomization.yaml +++ b/pkg/phase/testdata/valid_site/phases/kustomization.yaml @@ -6,3 +6,4 @@ resources: - clusterctl.yaml - kubernetes_apply.yaml - cluster_map.yaml + - phase_no_docentrypoint.yaml diff --git a/pkg/phase/testdata/valid_site/phases/phase_no_docentrypoint.yaml b/pkg/phase/testdata/valid_site/phases/phase_no_docentrypoint.yaml new file mode 100644 index 000000000..4e78f028f --- /dev/null +++ b/pkg/phase/testdata/valid_site/phases/phase_no_docentrypoint.yaml @@ -0,0 +1,9 @@ +apiVersion: airshipit.org/v1alpha1 +kind: Phase +metadata: + name: no_entry_point +config: + executorRef: + apiVersion: airshipit.org/v1alpha1 + kind: SomeExecutor + name: executor-name