From ff29f255e8c39669c54f6c9f111b9d3d821c1f05 Mon Sep 17 00:00:00 2001 From: Liming Liu Date: Wed, 13 Dec 2023 07:29:00 +0000 Subject: [PATCH] fix --- .../rollouts/validation/validation_test.go | 53 ++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/pkg/apis/rollouts/validation/validation_test.go b/pkg/apis/rollouts/validation/validation_test.go index 23982602e6..fbcac79e63 100644 --- a/pkg/apis/rollouts/validation/validation_test.go +++ b/pkg/apis/rollouts/validation/validation_test.go @@ -244,13 +244,54 @@ func TestValidateRolloutStrategyCanary(t *testing.T) { t.Run("only nginx/plugins support max weight value", func(t *testing.T) { anyWeight := int32(1) - invalidRo := ro.DeepCopy() - invalidRo.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{ - ALB: &v1alpha1.ALBTrafficRouting{RootService: "root-service"}, - MaxTrafficWeight: &anyWeight, + + type testCases struct { + trafficRouting *v1alpha1.RolloutTrafficRouting + expectError bool + expectedError string + } + + testCasesList := []testCases{ + { + trafficRouting: &v1alpha1.RolloutTrafficRouting{ + ALB: &v1alpha1.ALBTrafficRouting{RootService: "root-service"}, + MaxTrafficWeight: &anyWeight, + }, + expectError: true, + expectedError: InvalidCanaryMaxWeightOnlySupportInNginxAndPlugins, + }, + { + trafficRouting: &v1alpha1.RolloutTrafficRouting{ + Nginx: &v1alpha1.NginxTrafficRouting{ + StableIngress: "stable-ingress", + }, + MaxTrafficWeight: &anyWeight, + }, + expectError: false, + }, + { + trafficRouting: &v1alpha1.RolloutTrafficRouting{ + Plugins: map[string]json.RawMessage{ + "anyplugin": []byte(`{"key": "value"}`), + }, + MaxTrafficWeight: &anyWeight, + }, + expectError: false, + }, + } + + for _, testCase := range testCasesList { + invalidRo := ro.DeepCopy() + invalidRo.Spec.Strategy.Canary.Steps[0].SetWeight = &anyWeight + invalidRo.Spec.Strategy.Canary.TrafficRouting = testCase.trafficRouting + allErrs := ValidateRolloutStrategyCanary(invalidRo, field.NewPath("")) + if !testCase.expectError { + assert.Empty(t, allErrs) + continue + } + + assert.Equal(t, testCase.expectedError, allErrs[0].Detail) } - allErrs := ValidateRolloutStrategyCanary(invalidRo, field.NewPath("")) - assert.Equal(t, InvalidCanaryMaxWeightOnlySupportInNginxAndPlugins, allErrs[0].Detail) }) t.Run("invalid duration set in paused step", func(t *testing.T) {