Refactor e2e tests to use testify y httpexpect
This commit is contained in:
parent
046e2d959d
commit
f9624cbe46
80 changed files with 2280 additions and 2631 deletions
|
|
@ -19,8 +19,8 @@ package loadbalance
|
|||
import (
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
|
@ -28,11 +28,11 @@ import (
|
|||
var _ = framework.DescribeSetting("[Load Balancer] load-balance", func() {
|
||||
f := framework.NewDefaultFramework("lb-configmap")
|
||||
|
||||
BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeployment()
|
||||
})
|
||||
|
||||
It("should apply the configmap load-balance setting", func() {
|
||||
ginkgo.It("should apply the configmap load-balance setting", func() {
|
||||
host := "load-balance.com"
|
||||
|
||||
f.UpdateNginxConfigMapData("load-balance", "ewma")
|
||||
|
|
@ -44,7 +44,7 @@ var _ = framework.DescribeSetting("[Load Balancer] load-balance", func() {
|
|||
})
|
||||
|
||||
algorithm, err := f.GetLbAlgorithm(framework.EchoService, 80)
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(algorithm).Should(Equal("ewma"))
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
assert.Equal(ginkgo.GinkgoT(), algorithm, "ewma")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -18,13 +18,12 @@ package loadbalance
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/parnurzeal/gorequest"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
|
@ -32,7 +31,7 @@ import (
|
|||
var _ = framework.DescribeSetting("[Load Balancer] EWMA", func() {
|
||||
f := framework.NewDefaultFramework("ewma")
|
||||
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(3)
|
||||
f.SetNginxConfigMapData(map[string]string{
|
||||
"worker-processes": "2",
|
||||
|
|
@ -40,7 +39,7 @@ var _ = framework.DescribeSetting("[Load Balancer] EWMA", func() {
|
|||
)
|
||||
})
|
||||
|
||||
It("does not fail requests", func() {
|
||||
ginkgo.It("does not fail requests", func() {
|
||||
host := "load-balance.com"
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil))
|
||||
|
|
@ -50,21 +49,21 @@ var _ = framework.DescribeSetting("[Load Balancer] EWMA", func() {
|
|||
})
|
||||
|
||||
algorithm, err := f.GetLbAlgorithm(framework.EchoService, 80)
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(algorithm).Should(Equal("ewma"))
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
assert.Equal(ginkgo.GinkgoT(), algorithm, "ewma")
|
||||
|
||||
re, _ := regexp.Compile(fmt.Sprintf(`%v.*`, framework.EchoService))
|
||||
replicaRequestCount := map[string]int{}
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
_, body, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Set("Host", host).
|
||||
End()
|
||||
Expect(errs).Should(BeEmpty())
|
||||
body := f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusOK).Body().Raw()
|
||||
|
||||
replica := re.FindString(body)
|
||||
Expect(replica).ShouldNot(Equal(""))
|
||||
assert.NotEmpty(ginkgo.GinkgoT(), replica)
|
||||
|
||||
if _, ok := replicaRequestCount[replica]; !ok {
|
||||
replicaRequestCount[replica] = 1
|
||||
|
|
@ -78,6 +77,6 @@ var _ = framework.DescribeSetting("[Load Balancer] EWMA", func() {
|
|||
for _, v := range replicaRequestCount {
|
||||
actualCount += v
|
||||
}
|
||||
Expect(actualCount).Should(Equal(30))
|
||||
assert.Equal(ginkgo.GinkgoT(), actualCount, 30)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -18,13 +18,12 @@ package loadbalance
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/parnurzeal/gorequest"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
|
@ -32,12 +31,12 @@ import (
|
|||
var _ = framework.DescribeSetting("[Load Balancer] round-robin", func() {
|
||||
f := framework.NewDefaultFramework("round-robin")
|
||||
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(3)
|
||||
f.UpdateNginxConfigMapData("worker-processes", "1")
|
||||
})
|
||||
|
||||
It("should evenly distribute requests with round-robin (default algorithm)", func() {
|
||||
ginkgo.It("should evenly distribute requests with round-robin (default algorithm)", func() {
|
||||
host := "load-balance.com"
|
||||
|
||||
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil))
|
||||
|
|
@ -50,14 +49,14 @@ var _ = framework.DescribeSetting("[Load Balancer] round-robin", func() {
|
|||
replicaRequestCount := map[string]int{}
|
||||
|
||||
for i := 0; i < 600; i++ {
|
||||
_, body, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Set("Host", host).
|
||||
End()
|
||||
Expect(errs).Should(BeEmpty())
|
||||
body := f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusOK).Body().Raw()
|
||||
|
||||
replica := re.FindString(body)
|
||||
Expect(replica).ShouldNot(Equal(""))
|
||||
assert.NotEmpty(ginkgo.GinkgoT(), replica)
|
||||
|
||||
if _, ok := replicaRequestCount[replica]; !ok {
|
||||
replicaRequestCount[replica] = 1
|
||||
|
|
@ -67,7 +66,7 @@ var _ = framework.DescribeSetting("[Load Balancer] round-robin", func() {
|
|||
}
|
||||
|
||||
for _, v := range replicaRequestCount {
|
||||
Expect(v).Should(Equal(200))
|
||||
assert.Equal(ginkgo.GinkgoT(), v, 200)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue