@@ -35,6 +35,7 @@ import (
3535 "github.com/stretchr/testify/assert"
3636 "k8s.io/apimachinery/pkg/types"
3737 "k8s.io/apimachinery/pkg/util/wait"
38+ "k8s.io/utils/ptr"
3839
3940 apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
4041 "github.com/apache/apisix-ingress-controller/test/e2e/framework"
@@ -1642,6 +1643,14 @@ spec:
16421643 })
16431644
16441645 Context ("complex scenarios" , func () {
1646+ BeforeEach (func () {
1647+ By ("deploy nginx service" )
1648+ s .DeployNginx (framework.NginxOptions {
1649+ Namespace : s .Namespace (),
1650+ Replicas : ptr .To (int32 (1 )),
1651+ })
1652+ })
1653+
16451654 It ("multiple external services in one upstream" , func () {
16461655 upstreamName := s .Namespace ()
16471656 routeName := s .Namespace ()
@@ -1656,9 +1665,9 @@ spec:
16561665 ingressClassName: %s
16571666 externalNodes:
16581667 - type: Domain
1659- name: httpbin.org
1668+ name: httpbin-service-e2e-test
16601669 - type: Domain
1661- name: postman-echo.com
1670+ name: nginx
16621671`
16631672 var upstream apiv2.ApisixUpstream
16641673 applier .MustApplyAPIv2 (
@@ -1671,24 +1680,26 @@ spec:
16711680
16721681 By ("verify access to multiple services" )
16731682 time .Sleep (7 * time .Second )
1674- hasEtag := false // postman-echo.com
1675- hasNoEtag := false // httpbin.org
1683+ hasHttpbin := false
1684+ hasNginx := false
16761685 for range 20 {
1677- headers := s .NewAPISIXClient ().GET ("/ip" ).
1686+ expect := s .NewAPISIXClient ().GET ("/ip" ).
16781687 WithHeader ("Host" , "httpbin.org" ).
16791688 WithHeader ("X-Foo" , "bar" ).
1680- Expect ().
1681- Headers ().Raw ()
1682- if _ , ok := headers ["Etag" ]; ok {
1683- hasEtag = true
1684- } else {
1685- hasNoEtag = true
1689+ Expect ()
1690+
1691+ body := expect .Body ().Raw ()
1692+ if strings .Contains (body , "Hello" ) {
1693+ hasNginx = true
1694+ } else if strings .Contains (body , `"origin"` ) {
1695+ hasHttpbin = true
16861696 }
1687- if hasEtag && hasNoEtag {
1697+ if hasHttpbin && hasNginx {
16881698 break
16891699 }
1700+ time .Sleep (100 * time .Millisecond )
16901701 }
1691- assert .True (GinkgoT (), hasEtag && hasNoEtag , "both httpbin and postman should be accessed at least once" )
1702+ assert .True (GinkgoT (), hasHttpbin && hasNginx , "both httpbin and nginx should be accessed at least once" )
16921703 })
16931704
16941705 It ("should be able to use backends and upstreams together" , func () {
@@ -1703,7 +1714,7 @@ spec:
17031714 ingressClassName: %s
17041715 externalNodes:
17051716 - type: Domain
1706- name: postman-echo.com
1717+ name: nginx
17071718`
17081719 var upstream apiv2.ApisixUpstream
17091720 applier .MustApplyAPIv2 (
@@ -1742,24 +1753,25 @@ spec:
17421753 )
17431754 By ("verify access to multiple services" )
17441755 time .Sleep (7 * time .Second )
1745- hasEtag := false // postman-echo.com
1746- hasNoEtag := false // httpbin.org
1756+ hasNginx := false
1757+ hasHttpbin := false
17471758 for range 20 {
1748- headers := s .NewAPISIXClient ().GET ("/ip" ).
1759+ expect := s .NewAPISIXClient ().GET ("/ip" ).
17491760 WithHeader ("Host" , "httpbin.org" ).
17501761 WithHeader ("X-Foo" , "bar" ).
1751- Expect ().
1752- Headers ().Raw ()
1753- if _ , ok := headers [ "Etag" ]; ok {
1754- hasEtag = true
1755- } else {
1756- hasNoEtag = true
1762+ Expect ()
1763+ body := expect . Body ().Raw ()
1764+ if strings . Contains ( body , "Hello" ) {
1765+ hasNginx = true
1766+ } else if strings . Contains ( body , `"origin"` ) {
1767+ hasHttpbin = true
17571768 }
1758- if hasEtag && hasNoEtag {
1769+ if hasNginx && hasHttpbin {
17591770 break
17601771 }
1772+ time .Sleep (100 * time .Millisecond )
17611773 }
1762- assert .True (GinkgoT (), hasEtag && hasNoEtag , "both httpbin and postman should be accessed at least once" )
1774+ assert .True (GinkgoT (), hasNginx && hasHttpbin , "both nginx and httpbin should be accessed at least once" )
17631775 })
17641776 })
17651777 })
0 commit comments