|
8 | 8 | ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
|
9 | 9 | )
|
10 | 10 |
|
11 |
| -func TestSnippetsFilterValidation_Snippets(t *testing.T) { |
| 11 | +func TestSnippetsFilterValidation(t *testing.T) { |
12 | 12 | t.Parallel()
|
13 | 13 | k8sClient := getKubernetesClient(t)
|
14 | 14 |
|
@@ -43,129 +43,9 @@ func TestSnippetsFilterValidation_Snippets(t *testing.T) {
|
43 | 43 | },
|
44 | 44 | },
|
45 | 45 | },
|
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 |
| - }, |
166 | 46 | {
|
167 | 47 | name: "Validate duplicate contexts are not allowed",
|
168 |
| - wantErrors: []string{"Only one snippet allowed per context"}, |
| 48 | + wantErrors: []string{expectedSnippetsFilterContextError}, |
169 | 49 | spec: ngfAPIv1alpha1.SnippetsFilterSpec{
|
170 | 50 | Snippets: []ngfAPIv1alpha1.Snippet{
|
171 | 51 | {
|
|
0 commit comments