Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andyliuliming committed Dec 13, 2023
1 parent 0d4677b commit 9059e4d
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions pkg/apis/rollouts/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9059e4d

Please sign in to comment.