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
This commit is contained in:
Kostiantyn Kalynovskyi 2020-09-22 14:15:12 -05:00 committed by Kostyantyn Kalynovskyi
parent e6e56ffa2e
commit 300486482c
4 changed files with 52 additions and 1 deletions

View File

@ -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
}

View File

@ -194,7 +194,7 @@ func TestHelperListPhases(t *testing.T) {
}{
{
name: "Success phase list",
phaseLen: 2,
phaseLen: 3,
config: testConfig,
},
{

View File

@ -6,3 +6,4 @@ resources:
- clusterctl.yaml
- kubernetes_apply.yaml
- cluster_map.yaml
- phase_no_docentrypoint.yaml

View File

@ -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