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:
parent
e6e56ffa2e
commit
300486482c
@ -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
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ func TestHelperListPhases(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Success phase list",
|
||||
phaseLen: 2,
|
||||
phaseLen: 3,
|
||||
config: testConfig,
|
||||
},
|
||||
{
|
||||
|
@ -6,3 +6,4 @@ resources:
|
||||
- clusterctl.yaml
|
||||
- kubernetes_apply.yaml
|
||||
- cluster_map.yaml
|
||||
- phase_no_docentrypoint.yaml
|
||||
|
9
pkg/phase/testdata/valid_site/phases/phase_no_docentrypoint.yaml
vendored
Normal file
9
pkg/phase/testdata/valid_site/phases/phase_no_docentrypoint.yaml
vendored
Normal 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
|
Loading…
Reference in New Issue
Block a user