Skip to content

Commit c0da0aa

Browse files
committed
remove tests for OpenAPI schema validation fields
1 parent 7726dc5 commit c0da0aa

File tree

2 files changed

+7
-122
lines changed

2 files changed

+7
-122
lines changed

tests/cel/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ const (
5454
expectedTargetRefNameUniqueError = `TargetRef Name must be unique`
5555
)
5656

57+
// SnippetsFilter validation errors.
58+
const (
59+
expectedSnippetsFilterContextError = `Only one snippet allowed per context`
60+
)
61+
5762
const (
5863
defaultNamespace = "default"
5964
)

tests/cel/snippetsFilter_test.go

Lines changed: 2 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
99
)
1010

11-
func TestSnippetsFilterValidation_Snippets(t *testing.T) {
11+
func TestSnippetsFilterValidation(t *testing.T) {
1212
t.Parallel()
1313
k8sClient := getKubernetesClient(t)
1414

@@ -43,129 +43,9 @@ func TestSnippetsFilterValidation_Snippets(t *testing.T) {
4343
},
4444
},
4545
},
46-
{
47-
name: "Validate empty snippet value is not allowed",
48-
wantErrors: []string{"Invalid value: \"\""},
49-
spec: ngfAPIv1alpha1.SnippetsFilterSpec{
50-
Snippets: []ngfAPIv1alpha1.Snippet{
51-
{
52-
Context: ngfAPIv1alpha1.NginxContextHTTP,
53-
Value: "",
54-
},
55-
},
56-
},
57-
},
58-
{
59-
name: "Validate no snippets is not allowed",
60-
wantErrors: []string{"Invalid value: 0"},
61-
spec: ngfAPIv1alpha1.SnippetsFilterSpec{
62-
Snippets: []ngfAPIv1alpha1.Snippet{},
63-
},
64-
},
65-
{
66-
name: "Validate maximum number of snippets is allowed",
67-
spec: ngfAPIv1alpha1.SnippetsFilterSpec{
68-
Snippets: []ngfAPIv1alpha1.Snippet{
69-
{
70-
Context: ngfAPIv1alpha1.NginxContextMain,
71-
Value: "worker_processes 4;",
72-
},
73-
{
74-
Context: ngfAPIv1alpha1.NginxContextHTTP,
75-
Value: "limit_req zone=one burst=5 nodelay;",
76-
},
77-
{
78-
Context: ngfAPIv1alpha1.NginxContextHTTPServer,
79-
Value: "server_name example.com;",
80-
},
81-
{
82-
Context: ngfAPIv1alpha1.NginxContextHTTPServerLocation,
83-
Value: "deny all;",
84-
},
85-
},
86-
},
87-
},
88-
{
89-
name: "Validate more than maximum number of snippets is not allowed",
90-
wantErrors: []string{"Too many: 5: must have at most 4 items"},
91-
spec: ngfAPIv1alpha1.SnippetsFilterSpec{
92-
Snippets: []ngfAPIv1alpha1.Snippet{
93-
{
94-
Context: ngfAPIv1alpha1.NginxContextMain,
95-
Value: "worker_processes 4;",
96-
},
97-
{
98-
Context: ngfAPIv1alpha1.NginxContextHTTP,
99-
Value: "limit_req zone=one burst=5 nodelay;",
100-
},
101-
{
102-
Context: ngfAPIv1alpha1.NginxContextHTTPServer,
103-
Value: "server_name example.com;",
104-
},
105-
{
106-
Context: ngfAPIv1alpha1.NginxContextHTTPServerLocation,
107-
Value: "deny all;",
108-
},
109-
{
110-
Context: ngfAPIv1alpha1.NginxContextHTTPServerLocation,
111-
Value: "extra configuration",
112-
},
113-
},
114-
},
115-
},
116-
}
117-
118-
for _, tt := range tests {
119-
t.Run(tt.name, func(t *testing.T) {
120-
t.Parallel()
121-
snippetsFilter := &ngfAPIv1alpha1.SnippetsFilter{
122-
ObjectMeta: controllerruntime.ObjectMeta{
123-
Name: uniqueResourceName(testResourceName),
124-
Namespace: defaultNamespace,
125-
},
126-
Spec: tt.spec,
127-
}
128-
validateCrd(t, tt.wantErrors, snippetsFilter, k8sClient)
129-
})
130-
}
131-
}
132-
133-
func TestSnippetsFilterValidation_Context(t *testing.T) {
134-
t.Parallel()
135-
k8sClient := getKubernetesClient(t)
136-
137-
tests := []struct {
138-
name string
139-
wantErrors []string
140-
spec ngfAPIv1alpha1.SnippetsFilterSpec
141-
}{
142-
{
143-
name: "Validate empty context is not allowed",
144-
wantErrors: []string{"Unsupported value: \"\""},
145-
spec: ngfAPIv1alpha1.SnippetsFilterSpec{
146-
Snippets: []ngfAPIv1alpha1.Snippet{
147-
{
148-
Context: "",
149-
Value: "empty context configuration",
150-
},
151-
},
152-
},
153-
},
154-
{
155-
name: "Validate incorrect context is not allowed",
156-
wantErrors: []string{"Unsupported value: \"invalid.context\""},
157-
spec: ngfAPIv1alpha1.SnippetsFilterSpec{
158-
Snippets: []ngfAPIv1alpha1.Snippet{
159-
{
160-
Context: "invalid.context",
161-
Value: "invalid context configuration",
162-
},
163-
},
164-
},
165-
},
16646
{
16747
name: "Validate duplicate contexts are not allowed",
168-
wantErrors: []string{"Only one snippet allowed per context"},
48+
wantErrors: []string{expectedSnippetsFilterContextError},
16949
spec: ngfAPIv1alpha1.SnippetsFilterSpec{
17050
Snippets: []ngfAPIv1alpha1.Snippet{
17151
{

0 commit comments

Comments
 (0)