Adds tests

Signed-off-by: Arjun Naik <arjun@arjunnaik.in>

Kubernetes-commit: 8ab226263a18fa16afdb6fd14da63544095a8937
This commit is contained in:
Arjun Naik 2019-12-10 18:09:08 +01:00 committed by Kubernetes Publisher
parent 3af9a45dfd
commit fa550e796d
1 changed files with 70 additions and 0 deletions

View File

@ -1773,6 +1773,7 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
minReplicasVal := int32(2)
targetUtilizationVal := int32(80)
currentUtilizationVal := int32(50)
maxSelectPolicy := autoscalingv2beta2.MaxPolicySelect
metricLabelSelector, err := metav1.ParseToLabelSelector("label=value")
if err != nil {
t.Errorf("unable to parse label selector: %v", err)
@ -2417,6 +2418,75 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
},
},
},
{
"scale up behavior specified",
autoscalingv2beta2.HorizontalPodAutoscaler{
Spec: autoscalingv2beta2.HorizontalPodAutoscalerSpec{
ScaleTargetRef: autoscalingv2beta2.CrossVersionObjectReference{
Name: "behavior-target",
Kind: "Deployment",
},
MinReplicas: &minReplicasVal,
MaxReplicas: 10,
Metrics: []autoscalingv2beta2.MetricSpec{
{
Type: autoscalingv2beta2.ResourceMetricSourceType,
Resource: &autoscalingv2beta2.ResourceMetricSource{
Name: corev1.ResourceCPU,
Target: autoscalingv2beta2.MetricTarget{
Type: autoscalingv2beta2.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
},
Behavior: &autoscalingv2beta2.HorizontalPodAutoscalerBehavior{
ScaleUp: &autoscalingv2beta2.HPAScalingRules{
StabilizationWindowSeconds: utilpointer.Int32Ptr(30),
SelectPolicy: &maxSelectPolicy,
Policies: []autoscalingv2beta2.HPAScalingPolicy{
{Type: autoscalingv2beta2.PodsScalingPolicy, Value: 10, PeriodSeconds: 10},
{Type: autoscalingv2beta2.PercentScalingPolicy, Value: 10, PeriodSeconds: 10},
},
},
},
},
},
},
{
"scale down behavior specified",
autoscalingv2beta2.HorizontalPodAutoscaler{
Spec: autoscalingv2beta2.HorizontalPodAutoscalerSpec{
ScaleTargetRef: autoscalingv2beta2.CrossVersionObjectReference{
Name: "behavior-target",
Kind: "Deployment",
},
MinReplicas: &minReplicasVal,
MaxReplicas: 10,
Metrics: []autoscalingv2beta2.MetricSpec{
{
Type: autoscalingv2beta2.ResourceMetricSourceType,
Resource: &autoscalingv2beta2.ResourceMetricSource{
Name: corev1.ResourceCPU,
Target: autoscalingv2beta2.MetricTarget{
Type: autoscalingv2beta2.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
},
Behavior: &autoscalingv2beta2.HorizontalPodAutoscalerBehavior{
ScaleDown: &autoscalingv2beta2.HPAScalingRules{
StabilizationWindowSeconds: utilpointer.Int32Ptr(30),
Policies: []autoscalingv2beta2.HPAScalingPolicy{
{Type: autoscalingv2beta2.PodsScalingPolicy, Value: 10, PeriodSeconds: 10},
{Type: autoscalingv2beta2.PercentScalingPolicy, Value: 10, PeriodSeconds: 10},
},
},
},
},
},
},
}
for _, test := range testsV2beta2 {