From b02cfe694dc9fb161532c64315730f745a446d00 Mon Sep 17 00:00:00 2001 From: Erick Ramirez Date: Wed, 31 Jul 2024 19:33:12 -0500 Subject: [PATCH] Add unit test for a case where stableRS is not yet ready so we shouldnt patch the DestinationRule --- rollout/trafficrouting_test.go | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/rollout/trafficrouting_test.go b/rollout/trafficrouting_test.go index f358a18f64..07f9d74778 100644 --- a/rollout/trafficrouting_test.go +++ b/rollout/trafficrouting_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/argoproj/argo-rollouts/rollout/trafficrouting" "github.com/argoproj/argo-rollouts/rollout/trafficrouting/apisix" "github.com/stretchr/testify/assert" @@ -232,6 +233,40 @@ func TestRolloutUseDesiredWeight(t *testing.T) { f.run(getKey(r2, t)) } +func TestReconcileTrafficRoutingStableRSAvailability(t *testing.T) { + + steps := []v1alpha1.CanaryStep{ + { + SetWeight: pointer.Int32Ptr(10), + }, + } + + r := newCanaryRollout("foo", 10, nil, steps, pointer.Int32Ptr(1), intstr.FromInt(1), intstr.FromInt(0)) + r.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{ + Istio: &v1alpha1.IstioTrafficRouting{}, + } + roCtx := &rolloutContext{ + rollout: r, + log: logutil.WithRollout(r), + } + + // Create a function that implements this func(roCtx *rolloutContext) ([]trafficrouting.TrafficRoutingReconciler, error) + roCtx.newTrafficRoutingReconciler = func(roCtx *rolloutContext) ([]trafficrouting.TrafficRoutingReconciler, error) { + + return []trafficrouting.TrafficRoutingReconciler{ + newUnmockedFakeTrafficRoutingReconciler(), + }, nil + } + + r1 := newCanaryRollout("foo", 10, nil, steps, pointer.Int32Ptr(2), intstr.FromInt(1), intstr.FromInt(0)) + rs1 := newReplicaSetWithStatus(r1, 10, 0) + roCtx.stableRS = rs1 + + err := roCtx.reconcileTrafficRouting() + assert.NoError(t, err) + +} + func TestRolloutUseDesiredWeight100(t *testing.T) { f := newFixture(t) defer f.Close()