Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Ganesh <rahulgab@amazon.com>
  • Loading branch information
Rahul Ganesh committed Jul 17, 2024
1 parent 8bbc6c2 commit 6d04bd5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/cluster/cloudstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func cloudstackEntry() *ConfigManagerEntry {
if c.CloudStackDatacenter != nil {
return c.CloudStackDatacenter.Validate()
} else if c.Cluster.Spec.DatacenterRef.Kind == v1alpha1.CloudStackDatacenterKind { // We need this conditional check as CloudStackDatacenter will be nil for other providers
return fmt.Errorf("CloudStackDatacenterConfig name %s not found", c.Cluster.Spec.DatacenterRef.Name)
return fmt.Errorf("CloudStackDatacenterConfig %s not found", c.Cluster.Spec.DatacenterRef.Name)
}
return nil
},
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/cloudstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func TestParseConfigMissingCloudstackDatacenter(t *testing.T) {
g.Expect(got.CloudStackDatacenter).To(BeNil())
}

func TestValidateCloudStackDatacenterNotFoundError(t *testing.T) {
g := NewWithT(t)
got, _ := cluster.ParseConfigFromFile("testdata/cluster_cloudstack_missing_datacenter.yaml")
g.Expect(got.CloudStackDatacenter).To(BeNil())

cm, _ := cluster.NewDefaultConfigManager()
err := cm.Validate(got)
g.Expect(err).To(MatchError(ContainSubstring("CloudStackDatacenterConfig eksa-unit-test not found")))
}

func TestDefaultConfigClientBuilderBuildCloudStackClusterSuccess(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/nutanix.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func nutanixEntry() *ConfigManagerEntry {
if c.NutanixDatacenter != nil {
return c.NutanixDatacenter.Validate()
} else if c.Cluster.Spec.DatacenterRef.Kind == v1alpha1.NutanixDatacenterKind { // We need this conditional check as NutanixDatacenter will be nil for other providers
return fmt.Errorf("NutanixDatacenterConfig name %s not found", c.Cluster.Spec.DatacenterRef.Name)
return fmt.Errorf("NutanixDatacenterConfig %s not found", c.Cluster.Spec.DatacenterRef.Name)
}
return nil
},
Expand Down
5 changes: 5 additions & 0 deletions pkg/cluster/nutanix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func TestValidateNutanixEntry(t *testing.T) {

err = cm.Validate(config)
assert.NoError(t, err)

config.NutanixDatacenter = nil
err = cm.Validate(config)
assert.Error(t, err)
assert.Contains(t, err.Error(), "NutanixDatacenterConfig eksa-unit-test not found")
}

func TestNutanixConfigClientBuilder(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/tinkerbell.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func tinkerbellEntry() *ConfigManagerEntry {
return err
}
} else if c.Cluster.Spec.DatacenterRef.Kind == v1alpha1.TinkerbellDatacenterKind { // We need this conditional check as TinkerbellDatacenter will be nil for other providers
return fmt.Errorf("TinkerbellDatacenterConfig name %s not found", c.Cluster.Spec.DatacenterRef.Name)
return fmt.Errorf("TinkerbellDatacenterConfig %s not found", c.Cluster.Spec.DatacenterRef.Name)
}
return nil
},
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/tinkerbell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ func TestParseConfigFromFileTinkerbellCluster(t *testing.T) {
)
}

func TestValidateTinkerbellDatacenterNotFoundError(t *testing.T) {
g := NewWithT(t)
got, err := cluster.ParseConfigFromFile("testdata/cluster_tinkerbell_1_19.yaml")
g.Expect(err).NotTo(HaveOccurred())
got.TinkerbellDatacenter = nil
cm, _ := cluster.NewDefaultConfigManager()
err = cm.Validate(got)
g.Expect(err).To(MatchError(ContainSubstring("TinkerbellDatacenterConfig test not found")))
}

func TestDefaultConfigClientBuilderTinkerbellCluster(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func vsphereEntry() *ConfigManagerEntry {
if c.VSphereDatacenter != nil {
return c.VSphereDatacenter.Validate()
} else if c.Cluster.Spec.DatacenterRef.Kind == v1alpha1.VSphereDatacenterKind { // We need this conditional check as VSphereDatacenter will be nil for other providers
return fmt.Errorf("VSphereDatacenterConfig name %s not found", c.Cluster.Spec.DatacenterRef.Name)
return fmt.Errorf("VSphereDatacenterConfig %s not found", c.Cluster.Spec.DatacenterRef.Name)
}
return nil
},
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ func TestParseConfigMissingVSphereDatacenter(t *testing.T) {
g.Expect(got.VSphereDatacenter).To(BeNil())
}

func TestValidateVSphereDatacenterNotFoundError(t *testing.T) {
g := NewWithT(t)
got, _ := cluster.ParseConfigFromFile("testdata/cluster_vsphere_missing_datacenter.yaml")
g.Expect(got.VSphereDatacenter).To(BeNil())

cm, _ := cluster.NewDefaultConfigManager()
err := cm.Validate(got)
g.Expect(err).To(MatchError(ContainSubstring("VSphereDatacenterConfig eksa-unit-test2 not found")))
}

func TestDefaultConfigClientBuilderVSphereCluster(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
Expand Down

0 comments on commit 6d04bd5

Please sign in to comment.