From 270a176a39d34e1d0b213c9d190368919612db9c Mon Sep 17 00:00:00 2001 From: Sarasa Kisaragi Date: Wed, 1 Sep 2021 11:55:12 +0800 Subject: [PATCH] fix: e2e failure due to count returned by APISIX (#640) Signed-off-by: Ling Samuel --- test/e2e/scaffold/k8s.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/e2e/scaffold/k8s.go b/test/e2e/scaffold/k8s.go index 4d9519b948..2c6b3fdb7f 100644 --- a/test/e2e/scaffold/k8s.go +++ b/test/e2e/scaffold/k8s.go @@ -20,6 +20,8 @@ import ( "io/ioutil" "net/http" "net/url" + "strconv" + "strings" "time" "github.com/apache/apisix-ingress-controller/pkg/apisix" @@ -33,7 +35,26 @@ import ( ) type counter struct { - Count apisix.IntOrString `json:"count"` + Count intOrDescOneString `json:"count"` +} + +// intOrDescOneString will decrease 1 if incoming value is string formatted number +type intOrDescOneString struct { + Value int `json:"value"` +} + +func (ios *intOrDescOneString) UnmarshalJSON(p []byte) error { + delta := 0 + if strings.HasPrefix(string(p), `"`) { + delta = -1 + } + result := strings.Trim(string(p), `"`) + count, err := strconv.Atoi(result) + if err != nil { + return err + } + ios.Value = count + delta + return nil } // ApisixRoute is the ApisixRoute CRD definition. @@ -163,7 +184,7 @@ func (s *Scaffold) ensureNumApisixCRDsCreated(url string, desired int) error { if err != nil { return false, err } - count := c.Count.IntValue + count := c.Count.Value if count != desired { ginkgo.GinkgoT().Logf("mismatched number of items, expected %d but found %d", desired, count) return false, nil