-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathsample_test.go
70 lines (60 loc) · 1.69 KB
/
sample_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/nginx/nginx-gateway-fabric/tests/framework"
)
var _ = Describe("Basic test example", Label("functional"), func() {
files := []string{
"hello-world/apps.yaml",
"hello-world/gateway.yaml",
"hello-world/routes.yaml",
}
var ns core.Namespace
BeforeEach(func() {
ns = core.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "helloworld",
},
}
Expect(resourceManager.Apply([]client.Object{&ns})).To(Succeed())
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
})
AfterEach(func() {
Expect(resourceManager.DeleteFromFiles(files, ns.Name)).To(Succeed())
Expect(resourceManager.DeleteNamespace(ns.Name)).To(Succeed())
})
It("sends traffic", func() {
url := "http://foo.example.com/hello"
if portFwdPort != 0 {
url = fmt.Sprintf("http://foo.example.com:%s/hello", strconv.Itoa(portFwdPort))
}
Eventually(
func() error {
status, body, err := framework.Get(url, address, timeoutConfig.RequestTimeout, nil, nil)
if err != nil {
return err
}
if status != http.StatusOK {
return fmt.Errorf("status not 200; got %d", status)
}
expBody := "URI: /hello"
if !strings.Contains(body, expBody) {
return fmt.Errorf("bad body: got %s; expected %s", body, expBody)
}
return nil
}).
WithTimeout(timeoutConfig.RequestTimeout).
WithPolling(500 * time.Millisecond).
Should(Succeed())
})
})