diff --git a/test/e2e/crds/v2/route.go b/test/e2e/crds/v2/route.go index 2139579f..349bc049 100644 --- a/test/e2e/crds/v2/route.go +++ b/test/e2e/crds/v2/route.go @@ -35,6 +35,7 @@ import ( "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/utils/ptr" apiv2 "github.com/apache/apisix-ingress-controller/api/v2" "github.com/apache/apisix-ingress-controller/test/e2e/framework" @@ -1642,6 +1643,14 @@ spec: }) Context("complex scenarios", func() { + BeforeEach(func() { + By("deploy nginx service") + s.DeployNginx(framework.NginxOptions{ + Namespace: s.Namespace(), + Replicas: ptr.To(int32(1)), + }) + }) + It("multiple external services in one upstream", func() { upstreamName := s.Namespace() routeName := s.Namespace() @@ -1656,9 +1665,9 @@ spec: ingressClassName: %s externalNodes: - type: Domain - name: httpbin.org + name: httpbin-service-e2e-test - type: Domain - name: postman-echo.com + name: nginx ` var upstream apiv2.ApisixUpstream applier.MustApplyAPIv2( @@ -1671,24 +1680,26 @@ spec: By("verify access to multiple services") time.Sleep(7 * time.Second) - hasEtag := false // postman-echo.com - hasNoEtag := false // httpbin.org + hasHttpbin := false + hasNginx := false for range 20 { - headers := s.NewAPISIXClient().GET("/ip"). + expect := s.NewAPISIXClient().GET("/ip"). WithHeader("Host", "httpbin.org"). WithHeader("X-Foo", "bar"). - Expect(). - Headers().Raw() - if _, ok := headers["Etag"]; ok { - hasEtag = true - } else { - hasNoEtag = true + Expect() + + body := expect.Body().Raw() + if strings.Contains(body, "Hello") { + hasNginx = true + } else if strings.Contains(body, `"origin"`) { + hasHttpbin = true } - if hasEtag && hasNoEtag { + if hasHttpbin && hasNginx { break } + time.Sleep(100 * time.Millisecond) } - assert.True(GinkgoT(), hasEtag && hasNoEtag, "both httpbin and postman should be accessed at least once") + assert.True(GinkgoT(), hasHttpbin && hasNginx, "both httpbin and nginx should be accessed at least once") }) It("should be able to use backends and upstreams together", func() { @@ -1703,7 +1714,7 @@ spec: ingressClassName: %s externalNodes: - type: Domain - name: postman-echo.com + name: nginx ` var upstream apiv2.ApisixUpstream applier.MustApplyAPIv2( @@ -1742,24 +1753,25 @@ spec: ) By("verify access to multiple services") time.Sleep(7 * time.Second) - hasEtag := false // postman-echo.com - hasNoEtag := false // httpbin.org + hasNginx := false + hasHttpbin := false for range 20 { - headers := s.NewAPISIXClient().GET("/ip"). + expect := s.NewAPISIXClient().GET("/ip"). WithHeader("Host", "httpbin.org"). WithHeader("X-Foo", "bar"). - Expect(). - Headers().Raw() - if _, ok := headers["Etag"]; ok { - hasEtag = true - } else { - hasNoEtag = true + Expect() + body := expect.Body().Raw() + if strings.Contains(body, "Hello") { + hasNginx = true + } else if strings.Contains(body, `"origin"`) { + hasHttpbin = true } - if hasEtag && hasNoEtag { + if hasNginx && hasHttpbin { break } + time.Sleep(100 * time.Millisecond) } - assert.True(GinkgoT(), hasEtag && hasNoEtag, "both httpbin and postman should be accessed at least once") + assert.True(GinkgoT(), hasNginx && hasHttpbin, "both nginx and httpbin should be accessed at least once") }) }) })