Skip to content

Commit

Permalink
test: added test for setDefaultAutoScalerProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
samyakjain10 authored and bennycortese committed Jul 31, 2023
1 parent fecb3a5 commit c0a3878
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions api/v1beta1/azuremanagedcontrolplane_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

. "github.com/onsi/gomega"
"k8s.io/utils/pointer"
)

func TestAzureManagedControlPlane_SetDefaultSSHPublicKey(t *testing.T) {
Expand Down Expand Up @@ -53,3 +54,79 @@ func hardcodedAzureManagedControlPlaneWithSSHKey(sshPublicKey string) *AzureMana
},
}
}

func TestSetDefaultAutoScalerProfile(t *testing.T) {
g := NewWithT(t)

type test struct {
amcp *AzureManagedControlPlane
}

defaultAMP := &AzureManagedControlPlane{
Spec: AzureManagedControlPlaneSpec{
AutoScalerProfile: &AutoScalerProfile{
BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))),
Expander: (*Expander)(pointer.String(string(ExpanderRandom))),
MaxEmptyBulkDelete: pointer.String("10"),
MaxGracefulTerminationSec: pointer.String("600"),
MaxNodeProvisionTime: pointer.String("15m"),
MaxTotalUnreadyPercentage: pointer.String("45"),
NewPodScaleUpDelay: pointer.String("0s"),
OkTotalUnreadyCount: pointer.String("3"),
ScanInterval: pointer.String("10s"),
ScaleDownDelayAfterAdd: pointer.String("10m"),
ScaleDownDelayAfterDelete: pointer.String("10s"),
ScaleDownDelayAfterFailure: pointer.String("3m"),
ScaleDownUnneededTime: pointer.String("10m"),
ScaleDownUnreadyTime: pointer.String("20m"),
ScaleDownUtilizationThreshold: pointer.String("0.5"),
SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageFalse))),
SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsTrue))),
},
},
}

allFieldsAreNilTest := test{amcp: &AzureManagedControlPlane{
Spec: AzureManagedControlPlaneSpec{
AutoScalerProfile: &AutoScalerProfile{},
},
}}

allFieldsAreNilTest.amcp.setDefaultAutoScalerProfile()

g.Expect(allFieldsAreNilTest.amcp.Spec.AutoScalerProfile).To(Equal(defaultAMP.Spec.AutoScalerProfile))

expectedNotNil := &AzureManagedControlPlane{
Spec: AzureManagedControlPlaneSpec{
AutoScalerProfile: &AutoScalerProfile{
BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsTrue))),
Expander: (*Expander)(pointer.String(string(ExpanderLeastWaste))),
MaxEmptyBulkDelete: pointer.String("5"),
MaxGracefulTerminationSec: pointer.String("300"),
MaxNodeProvisionTime: pointer.String("10m"),
MaxTotalUnreadyPercentage: pointer.String("30"),
NewPodScaleUpDelay: pointer.String("30s"),
OkTotalUnreadyCount: pointer.String("5"),
ScanInterval: pointer.String("20s"),
ScaleDownDelayAfterAdd: pointer.String("5m"),
ScaleDownDelayAfterDelete: pointer.String("1m"),
ScaleDownDelayAfterFailure: pointer.String("2m"),
ScaleDownUnneededTime: pointer.String("5m"),
ScaleDownUnreadyTime: pointer.String("10m"),
ScaleDownUtilizationThreshold: pointer.String("0.4"),
SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageTrue))),
SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsFalse))),
},
},
}

allFieldsAreNotNilTest := test{amcp: &AzureManagedControlPlane{
Spec: AzureManagedControlPlaneSpec{
AutoScalerProfile: expectedNotNil.Spec.AutoScalerProfile,
},
}}

allFieldsAreNotNilTest.amcp.setDefaultAutoScalerProfile()

g.Expect(allFieldsAreNotNilTest.amcp.Spec.AutoScalerProfile).To(Equal(expectedNotNil.Spec.AutoScalerProfile))
}

0 comments on commit c0a3878

Please sign in to comment.