Skip to content

Commit ef18d34

Browse files
committed
update SnippetsPolicy test cases
1 parent 2e88005 commit ef18d34

File tree

7 files changed

+24
-116
lines changed

7 files changed

+24
-116
lines changed

tests/suite/manifests/snippets-policy/invalid-context-sp.yaml renamed to tests/suite/manifests/snippets-policy/empty-snippets-sp.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
apiVersion: gateway.nginx.org/v1alpha1
21
kind: SnippetsPolicy
2+
apiVersion: gateway.nginx.org/v1alpha1
33
metadata:
4-
name: invalid-context-sp
4+
name: empty-snippets-sp
55
spec:
66
targetRefs:
77
- group: gateway.networking.k8s.io
88
kind: Gateway
99
name: gateway
10-
snippets:
11-
- context: http
12-
value: "worker_priority 0;"

tests/suite/manifests/snippets-policy/gateway-2.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/suite/manifests/snippets-policy/invalid-duplicate-sp.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/suite/manifests/snippets-policy/location-sp.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/suite/manifests/snippets-policy/multi-target-sp.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/suite/manifests/snippets-policy/valid-sp.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ spec:
1414
value: "aio off;"
1515
- context: http.server
1616
value: "auth_delay 0s;"
17+
- context: http.server.location
18+
value: "allow 127.0.0.1;"

tests/suite/snippets_policy_test.go

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ var _ = Describe("SnippetsPolicy", Ordered, Label("functional", "snippets-policy
2222
files = []string{
2323
"snippets-policy/cafe.yaml",
2424
"snippets-policy/gateway.yaml",
25-
"snippets-policy/gateway-2.yaml",
2625
}
2726

2827
namespace = "snippets-policy"
2928

30-
nginxPodName string
31-
gatewayNsName = types.NamespacedName{Name: "gateway", Namespace: namespace}
29+
nginxPodName string
3230
)
3331

3432
BeforeAll(func() {
@@ -63,8 +61,6 @@ var _ = Describe("SnippetsPolicy", Ordered, Label("functional", "snippets-policy
6361
When("SnippetsPolicies are applied to the resources", func() {
6462
snippetsPolicy := []string{
6563
"snippets-policy/valid-sp.yaml",
66-
"snippets-policy/multi-target-sp.yaml",
67-
"snippets-policy/location-sp.yaml",
6864
}
6965

7066
BeforeAll(func() {
@@ -76,14 +72,10 @@ var _ = Describe("SnippetsPolicy", Ordered, Label("functional", "snippets-policy
7672
framework.AddNginxLogsAndEventsToReport(resourceManager, namespace)
7773
Expect(resourceManager.DeleteFromFiles(snippetsPolicy, namespace)).To(Succeed())
7874
})
79-
8075
Specify("snippetsPolicies are accepted", func() {
8176
snippetsPolicyNames := []string{
8277
"valid-sp",
83-
"multi-target-sp",
84-
"location-sp",
8578
}
86-
8779
for _, name := range snippetsPolicyNames {
8880
nsname := types.NamespacedName{Name: name, Namespace: namespace}
8981

@@ -95,6 +87,21 @@ var _ = Describe("SnippetsPolicy", Ordered, Label("functional", "snippets-policy
9587
}
9688
})
9789

90+
Specify("empty snippets policy is accepted", func() {
91+
files := []string{"snippets-policy/empty-snippets-sp.yaml"}
92+
93+
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
94+
95+
nsname := types.NamespacedName{Name: "empty-snippets-sp", Namespace: namespace}
96+
Eventually(checkForSnippetsPolicyToBeAccepted).
97+
WithArguments(nsname).
98+
WithTimeout(timeoutConfig.GetStatusTimeout).
99+
WithPolling(500 * time.Millisecond).
100+
Should(Succeed())
101+
102+
Expect(resourceManager.DeleteFromFiles(files, namespace)).To(Succeed())
103+
})
104+
98105
Context("verify working traffic", func() {
99106
It("should return a 200 response for HTTPRoute", func() {
100107
port := 80
@@ -116,11 +123,6 @@ var _ = Describe("SnippetsPolicy", Ordered, Label("functional", "snippets-policy
116123
Context("nginx directives", func() {
117124
var conf *framework.Payload
118125

119-
// gwNsName := fmt.Sprintf("%s-%s", namespace, "gateway")
120-
// mainContext := fmt.Sprintf("%s%s/SnippetsPolicy_main_", snippetsPolicyFilePrefix, gwNsName)
121-
// httpContext := fmt.Sprintf("%s%s/SnippetsPolicy_http_", snippetsPolicyFilePrefix, gwNsName)
122-
// serverContext := fmt.Sprintf("%s%s/http:80/SnippetsPolicy_server_", snippetsPolicyFilePrefix, gwNsName)
123-
124126
BeforeAll(func() {
125127
var err error
126128
conf, err = resourceManager.GetNginxConfig(nginxPodName, namespace, "")
@@ -137,71 +139,27 @@ var _ = Describe("SnippetsPolicy", Ordered, Label("functional", "snippets-policy
137139
{
138140
Directive: "worker_priority",
139141
Value: "0",
140-
File: "SnippetsPolicy_main_valid-sp.conf",
142+
File: "SnippetsPolicy_main_snippets-policy-valid-sp.conf",
141143
},
142144
{
143145
Directive: "aio",
144146
Value: "off",
145-
File: "SnippetsPolicy_http_valid-sp.conf",
147+
File: "SnippetsPolicy_http_snippets-policy-valid-sp.conf",
146148
},
147149
{
148150
Directive: "auth_delay",
149151
Value: "0s",
150-
File: "SnippetsPolicy_server_valid-sp.conf",
151-
},
152-
}),
153-
Entry("multi-target-sp", []framework.ExpectedNginxField{
154-
{
155-
Directive: "env",
156-
Value: "MULTI_TARGET;",
157-
File: "snippets-policy-gateway/SnippetsPolicy_main_multi-target-sp.conf",
152+
File: "SnippetsPolicy_server_snippets-policy-valid-sp.conf",
158153
},
159-
{
160-
Directive: "env",
161-
Value: "MULTI_TARGET;",
162-
File: "snippets-policy-gateway-2/SnippetsPolicy_main_multi-target-sp.conf",
163-
},
164-
}),
165-
Entry("location-sp", []framework.ExpectedNginxField{
166154
{
167155
Directive: "allow",
168156
Value: "127.0.0.1",
169-
File: "SnippetsPolicy_location_location-sp.conf",
157+
File: "SnippetsPolicy_location_snippets-policy-location-sp.conf",
170158
},
171159
}),
172160
)
173161
})
174162
})
175-
176-
When("SnippetsPolicy is invalid", func() {
177-
Specify("if directives already present in the config are used", func() {
178-
files := []string{"snippets-policy/invalid-duplicate-sp.yaml"}
179-
180-
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
181-
182-
Eventually(checkGatewayToHaveGatewayNotProgrammedCond).
183-
WithArguments(gatewayNsName).
184-
WithTimeout(timeoutConfig.GetStatusTimeout).
185-
WithPolling(500 * time.Millisecond).
186-
Should(Succeed())
187-
188-
Expect(resourceManager.DeleteFromFiles(files, namespace)).To(Succeed())
189-
})
190-
191-
Specify("if directives are provided in the wrong context", func() {
192-
files := []string{"snippets-policy/invalid-context-sp.yaml"}
193-
194-
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
195-
196-
Eventually(checkGatewayToHaveGatewayNotProgrammedCond).
197-
WithArguments(gatewayNsName).
198-
WithTimeout(timeoutConfig.GetStatusTimeout).
199-
WithPolling(500 * time.Millisecond).
200-
Should(Succeed())
201-
202-
Expect(resourceManager.DeleteFromFiles(files, namespace)).To(Succeed())
203-
})
204-
})
205163
})
206164

207165
func checkForSnippetsPolicyToBeAccepted(snippetsPolicyNsNames types.NamespacedName) error {

0 commit comments

Comments
 (0)