
Add NewBundleByPath function, that would return bundle built from the specified path argument Add CurrentContextEntryPoint method of the config object, that would allow easily get kustomize root path based on clusterType and phase. You can also leave phase arg empty string, which would try to return bundle for all phases Introduce changes to config pakage objects: - Manifest: SubPath: this is relative path to the root of the repository that contains directories with sites (SiteNames) PrimaryRepositoryName: this is a string that must correspond to a key of the Repositories map of manifest object, which is used to derive primary repository Repositories object is a map, map keys correspond to names of the directories where `document pull` command will download repositories defined in manifest prepended by manifest.TargetPath. Introduce new config method CurrentContextEntryPoint(), method takes TargetPath, PrimaryRepo.URL, SubPath, and clusterType and phase constructs a path to the entry point out of which the DocumentBundle should be build, and returns it to the caller. After that caller can build a bundle out of it, the bundle will contain documents relevant to particular cluster-type and phase. All objects that depend on bundle interface are updated to use the CurrentContextEntryPoint() method of the config object Relates-To: #99 Closes: #99 Change-Id: I99320c4cb626841d46f4c298b583e9af90b1dce4
115 lines
2.7 KiB
Go
115 lines
2.7 KiB
Go
package initinfra_test
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"opendev.org/airship/airshipctl/pkg/cluster/initinfra"
|
|
"opendev.org/airship/airshipctl/pkg/document"
|
|
"opendev.org/airship/airshipctl/pkg/environment"
|
|
"opendev.org/airship/airshipctl/pkg/k8s/client"
|
|
"opendev.org/airship/airshipctl/pkg/k8s/kubectl"
|
|
"opendev.org/airship/airshipctl/testutil/k8sutils"
|
|
)
|
|
|
|
type TestClient struct {
|
|
MockKubectl func() kubectl.Interface
|
|
MockClientset func() kubernetes.Interface
|
|
}
|
|
|
|
func (tc TestClient) ClientSet() kubernetes.Interface { return tc.MockClientset() }
|
|
func (tc TestClient) Kubectl() kubectl.Interface { return tc.MockKubectl() }
|
|
|
|
const (
|
|
kubeconfigPath = "testdata/kubeconfig.yaml"
|
|
filenameRC = "testdata/primary/site/test-site/ephemeral/initinfra/replicationcontroller.yaml"
|
|
airshipConfigFile = "testdata/config.yaml"
|
|
)
|
|
|
|
var (
|
|
DynamicClientError = errors.New("DynamicClientError")
|
|
)
|
|
|
|
func TestNewInfra(t *testing.T) {
|
|
rs := makeNewFakeRootSettings(t, kubeconfigPath, airshipConfigFile)
|
|
infra := initinfra.NewInfra(rs)
|
|
|
|
assert.NotNil(t, infra.RootSettings)
|
|
}
|
|
|
|
func TestDeploy(t *testing.T) {
|
|
rs := makeNewFakeRootSettings(t, kubeconfigPath, airshipConfigFile)
|
|
tf := k8sutils.NewFakeFactoryForRC(t, filenameRC)
|
|
defer tf.Cleanup()
|
|
|
|
infra := initinfra.NewInfra(rs)
|
|
infra.ClusterType = "ephemeral"
|
|
infra.DryRun = true
|
|
|
|
infra.FileSystem = document.NewDocumentFs()
|
|
|
|
kctl := kubectl.NewKubectl(tf)
|
|
tc := TestClient{
|
|
MockKubectl: func() kubectl.Interface { return kctl },
|
|
}
|
|
|
|
tests := []struct {
|
|
theInfra *initinfra.Infra
|
|
client client.Interface
|
|
prune bool
|
|
expectedError error
|
|
}{
|
|
{
|
|
client: TestClient{
|
|
MockKubectl: func() kubectl.Interface {
|
|
return kubectl.NewKubectl(k8sutils.
|
|
NewMockKubectlFactory().
|
|
WithDynamicClientByError(nil, DynamicClientError))
|
|
},
|
|
},
|
|
expectedError: DynamicClientError,
|
|
},
|
|
{
|
|
expectedError: nil,
|
|
prune: false,
|
|
client: tc,
|
|
},
|
|
{
|
|
expectedError: nil,
|
|
prune: true,
|
|
client: tc,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
infra.Prune = test.prune
|
|
infra.Client = test.client
|
|
actualErr := infra.Deploy()
|
|
assert.Equal(t, test.expectedError, actualErr)
|
|
}
|
|
}
|
|
|
|
// MakeNewFakeRootSettings takes kubeconfig path and directory path to fixture dir as argument.
|
|
func makeNewFakeRootSettings(t *testing.T, kp string, dir string) *environment.AirshipCTLSettings {
|
|
t.Helper()
|
|
rs := &environment.AirshipCTLSettings{}
|
|
|
|
akp, err := filepath.Abs(kp)
|
|
require.NoError(t, err)
|
|
|
|
adir, err := filepath.Abs(dir)
|
|
require.NoError(t, err)
|
|
|
|
rs.SetAirshipConfigPath(adir)
|
|
rs.SetKubeConfigPath(akp)
|
|
|
|
rs.InitConfig()
|
|
return rs
|
|
}
|