|
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) {
|
@@ -149,25 +149,52 @@ func TestGenerate(t *testing.T) {
|
149 | 149 | },
|
150 | 150 | }
|
151 | 151 |
|
| 152 | + g := NewWithT(t) |
| 153 | + |
| 154 | + checkResults := func(resFiles policies.GenerateResultFiles, expStrings []string) { |
| 155 | + g.Expect(resFiles).To(HaveLen(1)) |
| 156 | + |
| 157 | + for _, str := range expStrings { |
| 158 | + g.Expect(string(resFiles[0].Content)).To(ContainSubstring(str)) |
| 159 | + } |
| 160 | + } |
| 161 | + |
152 | 162 | for _, test := range tests {
|
153 |
| - t.Run(test.name, func(t *testing.T) { |
154 |
| - g := NewWithT(t) |
| 163 | + t.Run(test.name, func(_ *testing.T) { |
| 164 | + generator := clientsettings.NewGenerator() |
| 165 | + |
| 166 | + resFiles := generator.GenerateForServer([]policies.Policy{test.policy}, http.Server{}) |
| 167 | + checkResults(resFiles, test.expStrings) |
155 | 168 |
|
156 |
| - cfgString := string(clientsettings.Generate(test.policy, nil)) |
| 169 | + resFiles = generator.GenerateForLocation([]policies.Policy{test.policy}, http.Location{}) |
| 170 | + checkResults(resFiles, test.expStrings) |
157 | 171 |
|
158 |
| - for _, str := range test.expStrings { |
159 |
| - g.Expect(cfgString).To(ContainSubstring(str)) |
160 |
| - } |
| 172 | + resFiles = generator.GenerateForInternalLocation([]policies.Policy{test.policy}) |
| 173 | + checkResults(resFiles, test.expStrings) |
161 | 174 | })
|
162 | 175 | }
|
163 | 176 | }
|
164 | 177 |
|
165 |
| -func TestGeneratePanics(t *testing.T) { |
| 178 | +func TestGenerateNoPolicies(t *testing.T) { |
166 | 179 | g := NewWithT(t)
|
167 | 180 |
|
168 |
| - generate := func() { |
169 |
| - clientsettings.Generate(&policiesfakes.FakePolicy{}, nil) |
170 |
| - } |
| 181 | + generator := clientsettings.NewGenerator() |
| 182 | + |
| 183 | + resFiles := generator.GenerateForServer([]policies.Policy{}, http.Server{}) |
| 184 | + g.Expect(resFiles).To(BeEmpty()) |
| 185 | + |
| 186 | + resFiles = generator.GenerateForServer([]policies.Policy{&ngfAPI.ObservabilityPolicy{}}, http.Server{}) |
| 187 | + g.Expect(resFiles).To(BeEmpty()) |
| 188 | + |
| 189 | + resFiles = generator.GenerateForLocation([]policies.Policy{}, http.Location{}) |
| 190 | + g.Expect(resFiles).To(BeEmpty()) |
| 191 | + |
| 192 | + resFiles = generator.GenerateForLocation([]policies.Policy{&ngfAPI.ObservabilityPolicy{}}, http.Location{}) |
| 193 | + g.Expect(resFiles).To(BeEmpty()) |
| 194 | + |
| 195 | + resFiles = generator.GenerateForInternalLocation([]policies.Policy{}) |
| 196 | + g.Expect(resFiles).To(BeEmpty()) |
171 | 197 |
|
172 |
| - g.Expect(generate).To(Panic()) |
| 198 | + resFiles = generator.GenerateForInternalLocation([]policies.Policy{&ngfAPI.ObservabilityPolicy{}}) |
| 199 | + g.Expect(resFiles).To(BeEmpty()) |
173 | 200 | }
|
0 commit comments