Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: sbadiger <[email protected]>
  • Loading branch information
shreyas-badiger committed Aug 31, 2023
1 parent d8f93fe commit bd43f19
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ all: check-go test clean manager
# Run tests
.PHONY: test
test: generate fmt vet manifests
go test -v ./controllers/... ./api/... -coverprofile coverage.txt
go test ./controllers/... ./api/... -coverprofile coverage.txt

.PHONY: bdd
bdd:
Expand Down
78 changes: 78 additions & 0 deletions api/v1alpha1/instancegroup_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

type EksUnitTest struct {
InstanceGroup *InstanceGroup
Overrides *ValidationOverrides
}

func (u *EksUnitTest) Run(t *testing.T) string {
Expand All @@ -34,12 +35,15 @@ func (u *EksUnitTest) Run(t *testing.T) string {
}

func TestInstanceGroupSpecValidate(t *testing.T) {
launchconfiguration := LaunchConfiguration
type args struct {
instancegroup *InstanceGroup
overrides *ValidationOverrides
}
testFunction := func(t *testing.T, args args) string {
testCase := EksUnitTest{
InstanceGroup: args.instancegroup,
Overrides: args.overrides,
}
return testCase.Run(t)
}
Expand Down Expand Up @@ -432,6 +436,16 @@ func TestInstanceGroupSpecValidate(t *testing.T) {
},
want: "validation failed, HostResourceGroupArn must be a valid dedicated HostResourceGroup ARN",
},
{
name: "default to launch config instead of launch template",
args: args{
instancegroup: MockInstanceGroup("eks-fargate", "managed", nil, nil, basicFargateSpec()),
overrides: &ValidationOverrides{
scalingConfigurationOverride: &launchconfiguration,
},
},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -444,6 +458,70 @@ func TestInstanceGroupSpecValidate(t *testing.T) {
}
}

func TestScalingConfigOverride(t *testing.T) {
launchconfiguration := LaunchConfiguration
launchtemplate := LaunchTemplate
type args struct {
instancegroup *InstanceGroup
overrides *ValidationOverrides
}
testFunction := func(t *testing.T, args args) string {
testCase := EksUnitTest{
InstanceGroup: args.instancegroup,
Overrides: args.overrides,
}
return testCase.Run(t)
}
tests := []struct {
name string
args args
want ScalingConfigurationType
}{
{
name: "override default to launchconfig instead of launchtemplate",
args: args{
instancegroup: MockInstanceGroup("eks-fargate", "managed", nil, nil, basicFargateSpec()),
overrides: &ValidationOverrides{
scalingConfigurationOverride: &launchconfiguration,
},
},
want: LaunchConfiguration,
},
{
name: "no default overrides",
args: args{
instancegroup: MockInstanceGroup("eks-fargate", "managed", nil, nil, basicFargateSpec()),
overrides: &ValidationOverrides{},
},
want: LaunchTemplate,
},
{
name: "override default to launchtemplate",
args: args{
instancegroup: MockInstanceGroup("eks-fargate", "managed", nil, nil, basicFargateSpec()),
overrides: &ValidationOverrides{
scalingConfigurationOverride: &launchtemplate,
},
},
want: LaunchTemplate,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := testFunction(t, tt.args)
if err != "" {
t.Errorf("error:%v", err)
}
got := tt.args.instancegroup.Spec.EKSSpec.Type
if got != tt.want {
t.Errorf("%v: got %v, want %v", tt.name, got, tt.want)
}

})

}
}

func TestLockedAnnotation(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit bd43f19

Please sign in to comment.