Skip to content

Commit cdb28c7

Browse files
committed
Fix unit test
1 parent 71a332d commit cdb28c7

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

internal/mode/static/nginx/config/generator_test.go

+30-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config_test
22

33
import (
4-
"fmt"
54
"sort"
65
"testing"
76

@@ -144,15 +143,14 @@ func TestGenerate(t *testing.T) {
144143

145144
files := generator.Generate(conf)
146145

147-
g.Expect(files).To(HaveLen(17))
146+
g.Expect(files).To(HaveLen(16))
148147
arrange := func(i, j int) bool {
149148
return files[i].Path < files[j].Path
150149
}
151150
sort.Slice(files, arrange)
152151

153152
/*
154153
Order of files:
155-
/etc/nginx/conf.d/config-version.conf
156154
/etc/nginx/conf.d/http.conf
157155
/etc/nginx/conf.d/matches.json
158156
/etc/nginx/includes/http_snippet1.conf
@@ -172,13 +170,8 @@ func TestGenerate(t *testing.T) {
172170
*/
173171

174172
g.Expect(files[0].Type).To(Equal(file.TypeRegular))
175-
g.Expect(files[0].Path).To(Equal("/etc/nginx/conf.d/config-version.conf"))
176-
configVersion := string(files[0].Content)
177-
g.Expect(configVersion).To(ContainSubstring(fmt.Sprintf("return 200 %d", conf.Version)))
178-
179-
g.Expect(files[1].Type).To(Equal(file.TypeRegular))
180-
g.Expect(files[1].Path).To(Equal("/etc/nginx/conf.d/http.conf"))
181-
httpCfg := string(files[1].Content) // converting to string so that on failure gomega prints strings not byte arrays
173+
g.Expect(files[0].Path).To(Equal("/etc/nginx/conf.d/http.conf"))
174+
httpCfg := string(files[0].Content) // converting to string so that on failure gomega prints strings not byte arrays
182175
// Note: this only verifies that Generate() returns a byte array with upstream, server, and split_client blocks.
183176
// It does not test the correctness of those blocks. That functionality is covered by other tests in this package.
184177
g.Expect(httpCfg).To(ContainSubstring("listen 80"))
@@ -195,66 +188,66 @@ func TestGenerate(t *testing.T) {
195188
g.Expect(httpCfg).To(ContainSubstring("include /etc/nginx/includes/http_snippet1.conf;"))
196189
g.Expect(httpCfg).To(ContainSubstring("include /etc/nginx/includes/http_snippet2.conf;"))
197190

198-
g.Expect(files[2].Path).To(Equal("/etc/nginx/conf.d/matches.json"))
191+
g.Expect(files[1].Path).To(Equal("/etc/nginx/conf.d/matches.json"))
199192

200-
g.Expect(files[2].Type).To(Equal(file.TypeRegular))
193+
g.Expect(files[1].Type).To(Equal(file.TypeRegular))
201194
expString := "{}"
202-
g.Expect(string(files[2].Content)).To(Equal(expString))
195+
g.Expect(string(files[1].Content)).To(Equal(expString))
203196

204197
// snippet include files
205198
// content is not checked in this test.
206-
g.Expect(files[3].Path).To(Equal("/etc/nginx/includes/http_snippet1.conf"))
207-
g.Expect(files[4].Path).To(Equal("/etc/nginx/includes/http_snippet2.conf"))
208-
g.Expect(files[5].Path).To(Equal("/etc/nginx/includes/main_snippet1.conf"))
209-
g.Expect(files[6].Path).To(Equal("/etc/nginx/includes/main_snippet2.conf"))
199+
g.Expect(files[2].Path).To(Equal("/etc/nginx/includes/http_snippet1.conf"))
200+
g.Expect(files[3].Path).To(Equal("/etc/nginx/includes/http_snippet2.conf"))
201+
g.Expect(files[4].Path).To(Equal("/etc/nginx/includes/main_snippet1.conf"))
202+
g.Expect(files[5].Path).To(Equal("/etc/nginx/includes/main_snippet2.conf"))
210203

211-
g.Expect(files[7].Path).To(Equal("/etc/nginx/main-includes/deployment_ctx.json"))
212-
deploymentCtx := string(files[7].Content)
204+
g.Expect(files[6].Path).To(Equal("/etc/nginx/main-includes/deployment_ctx.json"))
205+
deploymentCtx := string(files[6].Content)
213206
g.Expect(deploymentCtx).To(ContainSubstring("\"integration\":\"ngf\""))
214207
g.Expect(deploymentCtx).To(ContainSubstring("\"cluster_id\":\"test-uid\""))
215208
g.Expect(deploymentCtx).To(ContainSubstring("\"installation_id\":\"test-uid-replicaSet\""))
216209
g.Expect(deploymentCtx).To(ContainSubstring("\"cluster_node_count\":1"))
217210

218-
g.Expect(files[8].Path).To(Equal("/etc/nginx/main-includes/main.conf"))
219-
mainConfStr := string(files[8].Content)
211+
g.Expect(files[7].Path).To(Equal("/etc/nginx/main-includes/main.conf"))
212+
mainConfStr := string(files[7].Content)
220213
g.Expect(mainConfStr).To(ContainSubstring("load_module modules/ngx_otel_module.so;"))
221214
g.Expect(mainConfStr).To(ContainSubstring("include /etc/nginx/includes/main_snippet1.conf;"))
222215
g.Expect(mainConfStr).To(ContainSubstring("include /etc/nginx/includes/main_snippet2.conf;"))
223216

224-
g.Expect(files[9].Path).To(Equal("/etc/nginx/main-includes/mgmt.conf"))
225-
mgmtConf := string(files[9].Content)
217+
g.Expect(files[8].Path).To(Equal("/etc/nginx/main-includes/mgmt.conf"))
218+
mgmtConf := string(files[8].Content)
226219
g.Expect(mgmtConf).To(ContainSubstring("usage_report endpoint=test-endpoint"))
227220
g.Expect(mgmtConf).To(ContainSubstring("license_token /etc/nginx/secrets/license.jwt"))
228221
g.Expect(mgmtConf).To(ContainSubstring("deployment_context /etc/nginx/main-includes/deployment_ctx.json"))
229222
g.Expect(mgmtConf).To(ContainSubstring("ssl_trusted_certificate /etc/nginx/secrets/mgmt-ca.crt"))
230223
g.Expect(mgmtConf).To(ContainSubstring("ssl_certificate /etc/nginx/secrets/mgmt-tls.crt"))
231224
g.Expect(mgmtConf).To(ContainSubstring("ssl_certificate_key /etc/nginx/secrets/mgmt-tls.key"))
232225

233-
g.Expect(files[10].Path).To(Equal("/etc/nginx/secrets/license.jwt"))
234-
g.Expect(string(files[10].Content)).To(Equal("license"))
226+
g.Expect(files[9].Path).To(Equal("/etc/nginx/secrets/license.jwt"))
227+
g.Expect(string(files[9].Content)).To(Equal("license"))
235228

236-
g.Expect(files[11].Path).To(Equal("/etc/nginx/secrets/mgmt-ca.crt"))
237-
g.Expect(string(files[11].Content)).To(Equal("ca"))
229+
g.Expect(files[10].Path).To(Equal("/etc/nginx/secrets/mgmt-ca.crt"))
230+
g.Expect(string(files[10].Content)).To(Equal("ca"))
238231

239-
g.Expect(files[12].Path).To(Equal("/etc/nginx/secrets/mgmt-tls.crt"))
240-
g.Expect(string(files[12].Content)).To(Equal("cert"))
232+
g.Expect(files[11].Path).To(Equal("/etc/nginx/secrets/mgmt-tls.crt"))
233+
g.Expect(string(files[11].Content)).To(Equal("cert"))
241234

242-
g.Expect(files[13].Path).To(Equal("/etc/nginx/secrets/mgmt-tls.key"))
243-
g.Expect(string(files[13].Content)).To(Equal("key"))
235+
g.Expect(files[12].Path).To(Equal("/etc/nginx/secrets/mgmt-tls.key"))
236+
g.Expect(string(files[12].Content)).To(Equal("key"))
244237

245-
g.Expect(files[14].Path).To(Equal("/etc/nginx/secrets/test-certbundle.crt"))
246-
certBundle := string(files[14].Content)
238+
g.Expect(files[13].Path).To(Equal("/etc/nginx/secrets/test-certbundle.crt"))
239+
certBundle := string(files[13].Content)
247240
g.Expect(certBundle).To(Equal("test-cert"))
248241

249-
g.Expect(files[15]).To(Equal(file.File{
242+
g.Expect(files[14]).To(Equal(file.File{
250243
Type: file.TypeSecret,
251244
Path: "/etc/nginx/secrets/test-keypair.pem",
252245
Content: []byte("test-cert\ntest-key"),
253246
}))
254247

255-
g.Expect(files[16].Path).To(Equal("/etc/nginx/stream-conf.d/stream.conf"))
256-
g.Expect(files[16].Type).To(Equal(file.TypeRegular))
257-
streamCfg := string(files[16].Content)
248+
g.Expect(files[15].Path).To(Equal("/etc/nginx/stream-conf.d/stream.conf"))
249+
g.Expect(files[15].Type).To(Equal(file.TypeRegular))
250+
streamCfg := string(files[15].Content)
258251
g.Expect(streamCfg).To(ContainSubstring("listen unix:/var/run/nginx/app.example.com-443.sock"))
259252
g.Expect(streamCfg).To(ContainSubstring("listen 443"))
260253
g.Expect(streamCfg).To(ContainSubstring("app.example.com unix:/var/run/nginx/app.example.com-443.sock"))

0 commit comments

Comments
 (0)