From c0a3878905a096b1ad1d89df24620901a47581c9 Mon Sep 17 00:00:00 2001 From: Samyak Jain Date: Thu, 20 Apr 2023 16:02:20 +0530 Subject: [PATCH] test: added test for setDefaultAutoScalerProfile --- .../azuremanagedcontrolplane_default_test.go | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/api/v1beta1/azuremanagedcontrolplane_default_test.go b/api/v1beta1/azuremanagedcontrolplane_default_test.go index b0cff2d7fe6..df91b4ffe59 100644 --- a/api/v1beta1/azuremanagedcontrolplane_default_test.go +++ b/api/v1beta1/azuremanagedcontrolplane_default_test.go @@ -20,6 +20,7 @@ import ( "testing" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" ) func TestAzureManagedControlPlane_SetDefaultSSHPublicKey(t *testing.T) { @@ -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)) +}