This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
feature.go
104 lines (80 loc) · 2.38 KB
/
feature.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package withouthost
import (
"fmt"
"net/http"
"github.com/cucumber/godog"
"github.com/cucumber/messages-go/v10"
tstate "github.com/aledbf/ingress-conformance-bdd/test/state"
"github.com/aledbf/ingress-conformance-bdd/test/utils"
)
var (
// holds state of the scenarario
state *tstate.Scenario
)
func aNewRandomNamespace() error {
var err error
state.Namespace, err = utils.CreateTestNamespace(utils.KubeClient)
if err != nil {
return err
}
return nil
}
func creatingObjectsFromDirectory(path string) error {
var err error
state.Ingress, err = utils.CreateFromPath(utils.KubeClient, path, state.Namespace, nil, nil)
if err != nil {
return err
}
return nil
}
func theIngressStatusShowsTheIPAddressOrFQDNWhereIsExposed() error {
if state.Ingress == nil {
return fmt.Errorf("feature without Ingress associated")
}
address, err := utils.WaitForIngressAddress(utils.KubeClient, state.Namespace,
state.Ingress.GetName(), utils.WaitForIngressAddressTimeout)
if err != nil {
return err
}
state.Address = address
return nil
}
func sendGETHTTPRequest() error {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%v", state.Address), nil)
if err != nil {
return err
}
err = state.SendRequest(req)
if err != nil {
return err
}
return nil
}
func theHTTPResponseCodeIs(arg1 int) error {
if state.StatusCode != arg1 {
return fmt.Errorf("expected status code %v but %v was returned",
arg1, state.StatusCode)
}
return nil
}
func headerIsNotPresent(arg1 string) error {
if value, ok := state.ResponseHeaders[arg1]; ok {
return fmt.Errorf("expected no header with name %v but exists (value %v)", arg1, value)
}
return nil
}
func FeatureContext(s *godog.Suite) {
s.Step(`^a new random namespace$`, aNewRandomNamespace)
s.Step(`^creating objects from directory "([^"]*)"$`, creatingObjectsFromDirectory)
s.Step(`^the ingress status shows the IP address or FQDN where is exposed$`, theIngressStatusShowsTheIPAddressOrFQDNWhereIsExposed)
s.Step(`^send GET HTTP request$`, sendGETHTTPRequest)
s.Step(`^the HTTP response code is (\d+)$`, theHTTPResponseCodeIs)
s.Step(`^Header "([^"]*)" is not present$`, headerIsNotPresent)
s.BeforeScenario(func(this *messages.Pickle) {
state = tstate.New(nil)
})
s.AfterScenario(func(*messages.Pickle, error) {
// delete namespace an all the content
_ = utils.DeleteKubeNamespace(utils.KubeClient, state.Namespace)
})
}