|
7 | 7 |
|
8 | 8 | ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
|
9 | 9 | "github.com/nginxinc/nginx-gateway-fabric/internal/framework/helpers"
|
10 |
| - "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/policies" |
11 |
| - "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/policies/clientsettings" |
12 |
| - "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/policies/policiesfakes" |
| 10 | + "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/http" |
| 11 | + "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" |
| 12 | + "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/clientsettings" |
13 | 13 | )
|
14 | 14 |
|
15 | 15 | func TestGenerate(t *testing.T) {
|
@@ -153,21 +153,52 @@ func TestGenerate(t *testing.T) {
|
153 | 153 | t.Run(test.name, func(t *testing.T) {
|
154 | 154 | g := NewWithT(t)
|
155 | 155 |
|
156 |
| - cfgString := string(clientsettings.Generate(test.policy, nil)) |
| 156 | + generator := clientsettings.NewGenerator() |
| 157 | + |
| 158 | + resFiles := generator.GenerateForServer([]policies.Policy{test.policy}, http.Server{}) |
| 159 | + g.Expect(resFiles).To(HaveLen(1)) |
| 160 | + |
| 161 | + for _, str := range test.expStrings { |
| 162 | + g.Expect(string(resFiles[0].Content)).To(ContainSubstring(str)) |
| 163 | + } |
| 164 | + |
| 165 | + resFiles = generator.GenerateForLocation([]policies.Policy{test.policy}, http.Location{}) |
| 166 | + g.Expect(resFiles).To(HaveLen(1)) |
157 | 167 |
|
158 | 168 | for _, str := range test.expStrings {
|
159 |
| - g.Expect(cfgString).To(ContainSubstring(str)) |
| 169 | + g.Expect(string(resFiles[0].Content)).To(ContainSubstring(str)) |
| 170 | + } |
| 171 | + |
| 172 | + resFiles = generator.GenerateForInternalLocation([]policies.Policy{test.policy}) |
| 173 | + g.Expect(resFiles).To(HaveLen(1)) |
| 174 | + |
| 175 | + for _, str := range test.expStrings { |
| 176 | + g.Expect(string(resFiles[0].Content)).To(ContainSubstring(str)) |
160 | 177 | }
|
161 | 178 | })
|
162 | 179 | }
|
163 | 180 | }
|
164 | 181 |
|
165 |
| -func TestGeneratePanics(t *testing.T) { |
| 182 | +func TestGenerateNoPolicies(t *testing.T) { |
166 | 183 | g := NewWithT(t)
|
167 | 184 |
|
168 |
| - generate := func() { |
169 |
| - clientsettings.Generate(&policiesfakes.FakePolicy{}, nil) |
170 |
| - } |
| 185 | + generator := clientsettings.NewGenerator() |
| 186 | + |
| 187 | + resFiles := generator.GenerateForServer([]policies.Policy{}, http.Server{}) |
| 188 | + g.Expect(resFiles).To(BeEmpty()) |
| 189 | + |
| 190 | + resFiles = generator.GenerateForServer([]policies.Policy{&ngfAPI.ObservabilityPolicy{}}, http.Server{}) |
| 191 | + g.Expect(resFiles).To(BeEmpty()) |
| 192 | + |
| 193 | + resFiles = generator.GenerateForLocation([]policies.Policy{}, http.Location{}) |
| 194 | + g.Expect(resFiles).To(BeEmpty()) |
| 195 | + |
| 196 | + resFiles = generator.GenerateForLocation([]policies.Policy{&ngfAPI.ObservabilityPolicy{}}, http.Location{}) |
| 197 | + g.Expect(resFiles).To(BeEmpty()) |
| 198 | + |
| 199 | + resFiles = generator.GenerateForInternalLocation([]policies.Policy{}) |
| 200 | + g.Expect(resFiles).To(BeEmpty()) |
171 | 201 |
|
172 |
| - g.Expect(generate).To(Panic()) |
| 202 | + resFiles = generator.GenerateForInternalLocation([]policies.Policy{&ngfAPI.ObservabilityPolicy{}}) |
| 203 | + g.Expect(resFiles).To(BeEmpty()) |
173 | 204 | }
|
0 commit comments