f4001bcffa
Isogen executor is not needed any more since there is iso build phase plan that runs two phases using generic containers. Relates-To: #440 Change-Id: I3600e82fa1d8a92cdf103d93cd4536bf4a713cca
129 lines
3.7 KiB
Go
Executable File
129 lines
3.7 KiB
Go
Executable File
/*
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package executors_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
"opendev.org/airship/airshipctl/pkg/config"
|
|
"opendev.org/airship/airshipctl/pkg/document"
|
|
"opendev.org/airship/airshipctl/pkg/events"
|
|
"opendev.org/airship/airshipctl/pkg/phase"
|
|
"opendev.org/airship/airshipctl/pkg/phase/executors"
|
|
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
|
)
|
|
|
|
const (
|
|
defaultMetadataPath = "metadata.yaml"
|
|
)
|
|
|
|
func TestRegisterExecutor(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
executorName string
|
|
registry map[schema.GroupVersionKind]ifc.ExecutorFactory
|
|
expectedGVK schema.GroupVersionKind
|
|
expectedErr error
|
|
}{
|
|
{
|
|
name: "register clusterctl executor",
|
|
executorName: executors.Clusterctl,
|
|
registry: make(map[schema.GroupVersionKind]ifc.ExecutorFactory),
|
|
expectedGVK: schema.GroupVersionKind{
|
|
Group: "airshipit.org",
|
|
Version: "v1alpha1",
|
|
Kind: "Clusterctl",
|
|
},
|
|
},
|
|
{
|
|
name: "register container executor",
|
|
executorName: executors.GenericContainer,
|
|
registry: make(map[schema.GroupVersionKind]ifc.ExecutorFactory),
|
|
expectedGVK: schema.GroupVersionKind{
|
|
Group: "airshipit.org",
|
|
Version: "v1alpha1",
|
|
Kind: "GenericContainer",
|
|
},
|
|
},
|
|
{
|
|
name: "register k8s applier executor",
|
|
executorName: executors.KubernetesApply,
|
|
registry: make(map[schema.GroupVersionKind]ifc.ExecutorFactory),
|
|
expectedGVK: schema.GroupVersionKind{
|
|
Group: "airshipit.org",
|
|
Version: "v1alpha1",
|
|
Kind: "KubernetesApply",
|
|
},
|
|
},
|
|
{
|
|
name: "register ephemeral executor",
|
|
executorName: executors.Ephemeral,
|
|
registry: make(map[schema.GroupVersionKind]ifc.ExecutorFactory),
|
|
expectedGVK: schema.GroupVersionKind{
|
|
Group: "airshipit.org",
|
|
Version: "v1alpha1",
|
|
Kind: "BootConfiguration",
|
|
},
|
|
},
|
|
}
|
|
for _, test := range testCases {
|
|
tt := test
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := executors.RegisterExecutor(tt.executorName, tt.registry)
|
|
require.NoError(t, err)
|
|
|
|
_, found := tt.registry[tt.expectedGVK]
|
|
assert.True(t, found)
|
|
})
|
|
}
|
|
}
|
|
|
|
func makeDefaultHelper(t *testing.T, targetPath, metaPath string) ifc.Helper {
|
|
t.Helper()
|
|
cfg := config.NewConfig()
|
|
cfg.Manifests[config.AirshipDefaultManifest].TargetPath = targetPath
|
|
cfg.Manifests[config.AirshipDefaultManifest].MetadataPath = metaPath
|
|
cfg.Manifests[config.AirshipDefaultManifest].Repositories[config.DefaultTestPhaseRepo].URLString = ""
|
|
cfg.SetLoadedConfigPath(".")
|
|
helper, err := phase.NewHelper(cfg)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, helper)
|
|
return helper
|
|
}
|
|
|
|
// executorDoc converts string to document object
|
|
func executorDoc(t *testing.T, s string) document.Document {
|
|
doc, err := document.NewDocumentFromBytes([]byte(s))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, doc)
|
|
return doc
|
|
}
|
|
|
|
func testBundleFactory(path string) document.BundleFactoryFunc {
|
|
return func() (document.Bundle, error) {
|
|
return document.NewBundleByPath(path)
|
|
}
|
|
}
|
|
|
|
func wrapError(err error) events.Event {
|
|
return events.NewEvent().WithErrorEvent(events.ErrorEvent{
|
|
Error: err,
|
|
})
|
|
}
|