This is an automated email from the ASF dual-hosted git repository.
kvn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new 18be04f test: add one more e2e case (#156)
18be04f is described below
commit 18be04ffdd5fe4761fadcb8bc3aac447180a1ca9
Author: Alex Zhang <[email protected]>
AuthorDate: Sat Jan 9 21:19:28 2021 +0800
test: add one more e2e case (#156)
* test: add one more e2e case
* chore: removed the useless method
* fix: readd the error handling
---
test/e2e/ingress/{route.go => resourcepushing.go} | 22 +++++------
test/e2e/ingress/sanity.go | 47 ++++++++++++++++++++++-
test/e2e/scaffold/crd.go | 2 +-
test/e2e/scaffold/etcd.go | 2 +-
test/e2e/scaffold/httpbin.go | 9 ++++-
test/e2e/scaffold/scaffold.go | 7 +---
6 files changed, 66 insertions(+), 23 deletions(-)
diff --git a/test/e2e/ingress/route.go b/test/e2e/ingress/resourcepushing.go
similarity index 84%
rename from test/e2e/ingress/route.go
rename to test/e2e/ingress/resourcepushing.go
index 8b88ebf..3a497c1 100644
--- a/test/e2e/ingress/route.go
+++ b/test/e2e/ingress/resourcepushing.go
@@ -30,16 +30,16 @@ var _ = ginkgo.Describe("upstream expansion", func() {
apiVersion: apisix.apache.org/v1
kind: ApisixRoute
metadata:
- name: httpbin-route
+ name: httpbin-route
spec:
- rules:
- - host: httpbin.com
- http:
- paths:
- - backend:
- serviceName: httpbin-service-e2e-test
- servicePort: 80
- path: /ip
+ rules:
+ - host: httpbin.com
+ http:
+ paths:
+ - backend:
+ serviceName: httpbin-service-e2e-test
+ servicePort: 80
+ path: /ip
`
s.CreateApisixRouteByString(apisixRoute)
@@ -48,8 +48,8 @@ spec:
err = s.EnsureNumApisixUpstreamsCreated(1)
assert.Nil(ginkgo.GinkgoT(), err, "Checking number of
upstreams")
scale := 2
- s.ScaleHTTPBIN(scale)
-
s.WaitUntilNumPodsCreatedE(s.Selector("app=httpbin-deployment-e2e-test"),
scale, 5, 5*time.Second)
+ err = s.ScaleHTTPBIN(scale)
+ assert.Nil(ginkgo.GinkgoT(), err)
time.Sleep(10 * time.Second) // wait for ingress to sync
ups, err := s.ListApisixUpstreams()
assert.Nil(ginkgo.GinkgoT(), err, "list upstreams error")
diff --git a/test/e2e/ingress/sanity.go b/test/e2e/ingress/sanity.go
index 3b107f9..5b2c5cd 100644
--- a/test/e2e/ingress/sanity.go
+++ b/test/e2e/ingress/sanity.go
@@ -18,10 +18,9 @@ import (
"encoding/json"
"net/http"
+ "github.com/api7/ingress-controller/test/e2e/scaffold"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
-
- "github.com/api7/ingress-controller/test/e2e/scaffold"
)
type ip struct {
@@ -60,3 +59,47 @@ var _ = ginkgo.Describe("single-route", func() {
// so here skip the IP address validation.
})
})
+
+var _ = ginkgo.Describe("double-routes", func() {
+ s := scaffold.NewDefaultScaffold()
+ ginkgo.It("double routes work independently", func() {
+ backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+ s.CreateApisixRoute("httpbin-route", []scaffold.ApisixRouteRule{
+ {
+ Host: "httpbin.com",
+ HTTP: scaffold.ApisixRouteRuleHTTP{
+ Paths:
[]scaffold.ApisixRouteRuleHTTPPath{
+ {
+ Path: "/ip",
+ Backend:
scaffold.ApisixRouteRuleHTTPBackend{
+ ServiceName:
backendSvc,
+ ServicePort:
backendSvcPort[0],
+ },
+ },
+ {
+ Path: "/json",
+ Backend:
scaffold.ApisixRouteRuleHTTPBackend{
+ ServiceName:
backendSvc,
+ ServicePort:
backendSvcPort[0],
+ },
+ },
+ },
+ },
+ },
+ })
+ err := s.EnsureNumApisixRoutesCreated(2)
+ assert.Nil(ginkgo.GinkgoT(), err, "checking number of routes")
+ err = s.EnsureNumApisixUpstreamsCreated(1)
+ assert.Nil(ginkgo.GinkgoT(), err, "checking number of
upstreams")
+ body := s.NewAPISIXClient().GET("/ip").WithHeader("Host",
"httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ var placeholder ip
+ err = json.Unmarshal([]byte(body), &placeholder)
+ assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
+
+ body = s.NewAPISIXClient().GET("/json").WithHeader("Host",
"httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+ var dummy map[string]interface{}
+ err = json.Unmarshal([]byte(body), &dummy)
+ assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling json")
+ // We don't care the json data, only make sure it's a normal
json string.
+ })
+})
diff --git a/test/e2e/scaffold/crd.go b/test/e2e/scaffold/crd.go
index 1d3d887..74cfe6b 100644
--- a/test/e2e/scaffold/crd.go
+++ b/test/e2e/scaffold/crd.go
@@ -161,7 +161,7 @@ func (s *Scaffold) EnsureNumApisixUpstreamsCreated(desired
int) error {
func (s *Scaffold) ListApisixUpstreams() ([]*v1.Upstream, error) {
host, err := s.apisixAdminServiceURL()
if err != nil {
- return nil, err
+ return err
}
u := url.URL{
Scheme: "http",
diff --git a/test/e2e/scaffold/etcd.go b/test/e2e/scaffold/etcd.go
index dac4398..6d9bdc9 100644
--- a/test/e2e/scaffold/etcd.go
+++ b/test/e2e/scaffold/etcd.go
@@ -134,7 +134,7 @@ func (s *Scaffold) waitAllEtcdPodsAvailable() error {
return waitExponentialBackoff(condFunc)
}
-func (s *Scaffold) Selector(label string) metav1.ListOptions {
+func (s *Scaffold) labelSelector(label string) metav1.ListOptions {
return metav1.ListOptions{
LabelSelector: label,
}
diff --git a/test/e2e/scaffold/httpbin.go b/test/e2e/scaffold/httpbin.go
index 3b85535..33401b3 100644
--- a/test/e2e/scaffold/httpbin.go
+++ b/test/e2e/scaffold/httpbin.go
@@ -16,6 +16,7 @@ package scaffold
import (
"fmt"
+ "time"
"github.com/gruntwork-io/terratest/modules/k8s"
corev1 "k8s.io/api/core/v1"
@@ -100,10 +101,14 @@ func (s *Scaffold) newHTTPBIN() (*corev1.Service, error) {
return svc, nil
}
-func (s *Scaffold) ScaleHTTPBIN(num int) error {
- httpbinDeployment := fmt.Sprintf(_httpbinDeploymentTemplate, num)
+// ScaleHTTPBIN scales the number of HTTPBIN pods to desired.
+func (s *Scaffold) ScaleHTTPBIN(desired int) error {
+ httpbinDeployment := fmt.Sprintf(_httpbinDeploymentTemplate, desired)
if err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions,
httpbinDeployment); err != nil {
return err
}
+ if err := k8s.WaitUntilNumPodsCreatedE(s.t, s.kubectlOptions,
s.labelSelector("app=httpbin-deployment-e2e-test"), desired, 5, 5*time.Second);
err != nil {
+ return err
+ }
return nil
}
diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go
index b5e291f..c4117ad 100644
--- a/test/e2e/scaffold/scaffold.go
+++ b/test/e2e/scaffold/scaffold.go
@@ -33,7 +33,6 @@ import (
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
)
@@ -159,7 +158,7 @@ func (s *Scaffold) beforeEach() {
// We don't use k8s.WaitUntilServiceAvailable since it hacks for
Minikube.
//err = s.waitAllEtcdPodsAvailable()
- err = k8s.WaitUntilNumPodsCreatedE(s.t, s.kubectlOptions,
s.Selector("app=etcd-deployment-e2e-test"), 1, 5, 2*time.Second)
+ err = k8s.WaitUntilNumPodsCreatedE(s.t, s.kubectlOptions,
s.labelSelector("app=etcd-deployment-e2e-test"), 1, 5, 2*time.Second)
assert.Nil(s.t, err, "waiting for etcd ready")
s.apisixService, err = s.newAPISIX()
@@ -210,7 +209,3 @@ func waitExponentialBackoff(condFunc func() (bool, error))
error {
}
return wait.ExponentialBackoff(backoff, condFunc)
}
-
-func (s *Scaffold) WaitUntilNumPodsCreatedE(selector metav1.ListOptions,
desiredCount int, retries int, interval time.Duration) error {
- return k8s.WaitUntilNumPodsCreatedE(s.t, s.kubectlOptions, selector,
desiredCount, retries, interval)
-}