Skip to content

Commit

Permalink
add factory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tatlat committed Jan 10, 2024
1 parent b0b543d commit 1cdfbbd
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/clusterapi/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ func TestClusterCASecretName(t *testing.T) {
g.Expect(clusterapi.ClusterCASecretName("my-cluster")).To(Equal("my-cluster-ca"))
}

func TestClusterKubeconfigSecretName(t *testing.T) {
g := NewWithT(t)
g.Expect(clusterapi.ClusterKubeconfigSecretName("my-cluster")).To(Equal("my-cluster-kubeconfig"))
}

func TestInitialTemplateNamesForWorkers(t *testing.T) {
tests := []struct {
name string
Expand Down
41 changes: 41 additions & 0 deletions pkg/dependencies/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type factoryTest struct {
type provider string

const (
docker provider = "docker"
vsphere provider = "vsphere"
tinkerbell provider = "tinkerbell"
nutanix provider = "nutanix"
Expand All @@ -60,6 +61,8 @@ func newTest(t *testing.T, p provider) *factoryTest {
}

switch p {
case docker:
f.clusterConfigFile = "testdata/cluster_docker.yaml"
case vsphere:
f.clusterConfigFile = "testdata/cluster_vsphere.yaml"
case tinkerbell:
Expand All @@ -86,6 +89,44 @@ func newTest(t *testing.T, p provider) *factoryTest {
return f
}

func TestFactoryBuildWithKubeconfigReader(t *testing.T) {
tests := []struct {
provider provider
exists bool
}{
{
provider: docker,
},
{
provider: vsphere,
},
{
provider: docker,
exists: true,
},
}

for _, tc := range tests {
tt := newTest(t, tc.provider)
var deps *dependencies.Dependencies
if tc.exists {
factory := dependencies.NewFactory()
deps, _ = factory.WithKubeconfigReader(tt.clusterSpec.Cluster).Build(context.Background())
tt.Expect(deps.KubeconfigReader).ToNot(BeNil())
deps, err := factory.WithKubeconfigReader(tt.clusterSpec.Cluster).Build(context.Background())
tt.Expect(err).To(BeNil())
tt.Expect(deps.KubeconfigReader).NotTo(BeNil())
} else {
deps, err := dependencies.NewFactory().
WithLocalExecutables().
WithKubeconfigReader(tt.clusterSpec.Cluster).
Build(context.Background())
tt.Expect(err).To(BeNil())
tt.Expect(deps.KubeconfigReader).NotTo(BeNil())
}
}
}

func TestFactoryBuildWithProvidervSphere(t *testing.T) {
tt := newTest(t, vsphere)
deps, err := dependencies.NewFactory().
Expand Down
35 changes: 35 additions & 0 deletions pkg/dependencies/testdata/cluster_docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: Cluster
metadata:
name: test-cluster
namespace: default
spec:
clusterNetwork:
cniConfig:
cilium: {}
pods:
cidrBlocks:
- 192.168.0.0/16
services:
cidrBlocks:
- 10.96.0.0/12
controlPlaneConfiguration:
count: 1
datacenterRef:
kind: DockerDatacenterConfig
name: test-cluster
kubernetesVersion: "1.21"
managementCluster:
name: test-cluster
workerNodeGroupConfigurations:
- count: 1
name: md-0

---
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: DockerDatacenterConfig
metadata:
name: test-cluster
namespace: default
spec: {}

0 comments on commit 1cdfbbd

Please sign in to comment.