mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
pkg/router/istio: add test for mirrorWeight
This commit is contained in:
+59
-50
@@ -91,69 +91,78 @@ func TestIstioRouter_SetRoutes(t *testing.T) {
|
||||
err := router.Reconcile(mocks.canary)
|
||||
require.NoError(t, err)
|
||||
|
||||
p, c, m, err := router.GetRoutes(mocks.canary)
|
||||
require.NoError(t, err)
|
||||
|
||||
p = 60
|
||||
c = 40
|
||||
m = false
|
||||
|
||||
err = router.SetRoutes(mocks.canary, p, c, m)
|
||||
require.NoError(t, err)
|
||||
|
||||
vs, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
pHost := fmt.Sprintf("%s-primary", mocks.canary.Spec.TargetRef.Name)
|
||||
cHost := fmt.Sprintf("%s-canary", mocks.canary.Spec.TargetRef.Name)
|
||||
pRoute := istiov1alpha3.DestinationWeight{}
|
||||
cRoute := istiov1alpha3.DestinationWeight{}
|
||||
var mirror *istiov1alpha3.Destination
|
||||
|
||||
for _, http := range vs.Spec.Http {
|
||||
for _, route := range http.Route {
|
||||
if route.Destination.Host == pHost {
|
||||
pRoute = route
|
||||
}
|
||||
if route.Destination.Host == cHost {
|
||||
cRoute = route
|
||||
mirror = http.Mirror
|
||||
t.Run("normal", func(t *testing.T) {
|
||||
p, c := 60, 40
|
||||
err := router.SetRoutes(mocks.canary, p, c, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
vs, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
var pRoute, cRoute istiov1alpha3.DestinationWeight
|
||||
var mirror *istiov1alpha3.Destination
|
||||
for _, http := range vs.Spec.Http {
|
||||
for _, route := range http.Route {
|
||||
if route.Destination.Host == pHost {
|
||||
pRoute = route
|
||||
}
|
||||
if route.Destination.Host == cHost {
|
||||
cRoute = route
|
||||
mirror = http.Mirror
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.Equal(t, p, pRoute.Weight)
|
||||
assert.Equal(t, c, cRoute.Weight)
|
||||
assert.Nil(t, mirror)
|
||||
assert.Equal(t, p, pRoute.Weight)
|
||||
assert.Equal(t, c, cRoute.Weight)
|
||||
assert.Nil(t, mirror)
|
||||
|
||||
mirror = nil
|
||||
p = 100
|
||||
c = 0
|
||||
m = true
|
||||
})
|
||||
|
||||
err = router.SetRoutes(mocks.canary, p, c, m)
|
||||
require.NoError(t, err)
|
||||
t.Run("mirror", func(t *testing.T) {
|
||||
for _, w := range []float64{0, 10, 50} {
|
||||
p, c := 100, 0
|
||||
|
||||
vs, err = mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
// set mirror weight
|
||||
mocks.canary.Spec.Analysis.MirrorWeight = w
|
||||
err := router.SetRoutes(mocks.canary, p, c, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, http := range vs.Spec.Http {
|
||||
for _, route := range http.Route {
|
||||
if route.Destination.Host == pHost {
|
||||
pRoute = route
|
||||
vs, err := mocks.meshClient.NetworkingV1alpha3().VirtualServices("default").Get("podinfo", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
var pRoute, cRoute istiov1alpha3.DestinationWeight
|
||||
var mirror *istiov1alpha3.Destination
|
||||
var mirrorWeight *istiov1alpha3.Percent
|
||||
for _, http := range vs.Spec.Http {
|
||||
for _, route := range http.Route {
|
||||
if route.Destination.Host == pHost {
|
||||
pRoute = route
|
||||
}
|
||||
if route.Destination.Host == cHost {
|
||||
cRoute = route
|
||||
mirror = http.Mirror
|
||||
mirrorWeight = http.MirrorPercentage
|
||||
}
|
||||
}
|
||||
}
|
||||
if route.Destination.Host == cHost {
|
||||
cRoute = route
|
||||
mirror = http.Mirror
|
||||
|
||||
assert.Equal(t, p, pRoute.Weight)
|
||||
assert.Equal(t, c, cRoute.Weight)
|
||||
if assert.NotNil(t, mirror) {
|
||||
assert.Equal(t, cHost, mirror.Host)
|
||||
}
|
||||
|
||||
if w > 0 && assert.NotNil(t, mirrorWeight) {
|
||||
assert.Equal(t, w, mirrorWeight.Value)
|
||||
} else {
|
||||
assert.Nil(t, mirrorWeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.Equal(t, p, pRoute.Weight)
|
||||
assert.Equal(t, c, cRoute.Weight)
|
||||
if assert.NotNil(t, mirror) {
|
||||
assert.Equal(t, cHost, mirror.Host)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestIstioRouter_GetRoutes(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user