Skip to content

Commit 3ac7115

Browse files
committed
update tests
1 parent 778b4d8 commit 3ac7115

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

internal/configs/version1/template_test.go

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,162 @@ func TestExecuteTemplate_ForMergeableIngressForNGINXPlusWithPathRegexAnnotationO
264264
}
265265
}
266266

267+
func TestExecuteTemplate_ForMainForNGINXWithCustomTLSPassthroughPort(t *testing.T) {
268+
t.Parallel()
269+
270+
tmpl := newNGINXMainTmpl(t)
271+
buf := &bytes.Buffer{}
272+
273+
err := tmpl.Execute(buf, mainCfgCustomTLSPassthroughPort)
274+
t.Log(buf.String())
275+
if err != nil {
276+
t.Fatalf("Failed to write template %v", err)
277+
}
278+
279+
wantDirectives := []string{
280+
"listen 8443;",
281+
"listen [::]:8443;",
282+
"proxy_pass $dest_internal_passthrough",
283+
}
284+
285+
mainConf := buf.String()
286+
for _, want := range wantDirectives {
287+
if !strings.Contains(mainConf, want) {
288+
t.Errorf("want %q in generated config", want)
289+
}
290+
}
291+
}
292+
293+
func TestExecuteTemplate_ForMainForNGINXPlusWithCustomTLSPassthroughPort(t *testing.T) {
294+
t.Parallel()
295+
296+
tmpl := newNGINXPlusMainTmpl(t)
297+
buf := &bytes.Buffer{}
298+
299+
err := tmpl.Execute(buf, mainCfgCustomTLSPassthroughPort)
300+
t.Log(buf.String())
301+
if err != nil {
302+
t.Fatalf("Failed to write template %v", err)
303+
}
304+
305+
wantDirectives := []string{
306+
"listen 8443;",
307+
"listen [::]:8443;",
308+
"proxy_pass $dest_internal_passthrough",
309+
}
310+
311+
mainConf := buf.String()
312+
for _, want := range wantDirectives {
313+
if !strings.Contains(mainConf, want) {
314+
t.Errorf("want %q in generated config", want)
315+
}
316+
}
317+
}
318+
319+
func TestExecuteTemplate_ForMainForNGINXWithoutCustomTLSPassthroughPort(t *testing.T) {
320+
t.Parallel()
321+
322+
tmpl := newNGINXMainTmpl(t)
323+
buf := &bytes.Buffer{}
324+
325+
err := tmpl.Execute(buf, mainCfg)
326+
t.Log(buf.String())
327+
if err != nil {
328+
t.Fatalf("Failed to write template %v", err)
329+
}
330+
331+
wantDirectives := []string{
332+
"listen 443;",
333+
"listen [::]:443;",
334+
"proxy_pass $dest_internal_passthrough",
335+
}
336+
337+
mainConf := buf.String()
338+
for _, want := range wantDirectives {
339+
if !strings.Contains(mainConf, want) {
340+
t.Errorf("want %q in generated config", want)
341+
}
342+
}
343+
}
344+
345+
func TestExecuteTemplate_ForMainForNGINXPlusWithoutCustomTLSPassthroughPort(t *testing.T) {
346+
t.Parallel()
347+
348+
tmpl := newNGINXPlusMainTmpl(t)
349+
buf := &bytes.Buffer{}
350+
351+
err := tmpl.Execute(buf, mainCfg)
352+
t.Log(buf.String())
353+
if err != nil {
354+
t.Fatalf("Failed to write template %v", err)
355+
}
356+
357+
wantDirectives := []string{
358+
"listen 443;",
359+
"listen [::]:443;",
360+
"proxy_pass $dest_internal_passthrough",
361+
}
362+
363+
mainConf := buf.String()
364+
for _, want := range wantDirectives {
365+
if !strings.Contains(mainConf, want) {
366+
t.Errorf("want %q in generated config", want)
367+
}
368+
}
369+
}
370+
371+
func TestExecuteTemplate_ForMainForNGINXTLSPassthroughDisabled(t *testing.T) {
372+
t.Parallel()
373+
374+
tmpl := newNGINXMainTmpl(t)
375+
buf := &bytes.Buffer{}
376+
377+
err := tmpl.Execute(buf, mainCfgWithoutTLSPassthrough)
378+
t.Log(buf.String())
379+
if err != nil {
380+
t.Fatalf("Failed to write template %v", err)
381+
}
382+
383+
unwantDirectives := []string{
384+
"listen 8443;",
385+
"listen [::]:8443;",
386+
"proxy_pass $dest_internal_passthrough",
387+
}
388+
389+
mainConf := buf.String()
390+
for _, want := range unwantDirectives {
391+
if strings.Contains(mainConf, want) {
392+
t.Errorf("unwant %q in generated config", want)
393+
}
394+
}
395+
}
396+
397+
func TestExecuteTemplate_ForMainForNGINXPlusTLSPassthroughPortDisabled(t *testing.T) {
398+
t.Parallel()
399+
400+
tmpl := newNGINXPlusMainTmpl(t)
401+
buf := &bytes.Buffer{}
402+
403+
err := tmpl.Execute(buf, mainCfgWithoutTLSPassthrough)
404+
t.Log(buf.String())
405+
if err != nil {
406+
t.Fatalf("Failed to write template %v", err)
407+
}
408+
409+
unwantDirectives := []string{
410+
"listen 443;",
411+
"listen [::]:443;",
412+
"proxy_pass $dest_internal_passthrough",
413+
}
414+
415+
mainConf := buf.String()
416+
for _, want := range unwantDirectives {
417+
if strings.Contains(mainConf, want) {
418+
t.Errorf("unwant %q in generated config", want)
419+
}
420+
}
421+
}
422+
267423
func newNGINXPlusIngressTmpl(t *testing.T) *template.Template {
268424
t.Helper()
269425
tmpl, err := template.New("nginx-plus.ingress.tmpl").Funcs(helperFunctions).ParseFiles("nginx-plus.ingress.tmpl")
@@ -597,6 +753,57 @@ var (
597753
VariablesHashBucketSize: 256,
598754
VariablesHashMaxSize: 1024,
599755
TLSPassthrough: true,
756+
TLSPassthroughPort: 443,
757+
}
758+
759+
mainCfgCustomTLSPassthroughPort = MainConfig{
760+
ServerNamesHashMaxSize: "512",
761+
ServerTokens: "off",
762+
WorkerProcesses: "auto",
763+
WorkerCPUAffinity: "auto",
764+
WorkerShutdownTimeout: "1m",
765+
WorkerConnections: "1024",
766+
WorkerRlimitNofile: "65536",
767+
LogFormat: []string{"$remote_addr", "$remote_user"},
768+
LogFormatEscaping: "default",
769+
StreamSnippets: []string{"# comment"},
770+
StreamLogFormat: []string{"$remote_addr", "$remote_user"},
771+
StreamLogFormatEscaping: "none",
772+
ResolverAddresses: []string{"example.com", "127.0.0.1"},
773+
ResolverIPV6: false,
774+
ResolverValid: "10s",
775+
ResolverTimeout: "15s",
776+
KeepaliveTimeout: "65s",
777+
KeepaliveRequests: 100,
778+
VariablesHashBucketSize: 256,
779+
VariablesHashMaxSize: 1024,
780+
TLSPassthrough: true,
781+
TLSPassthroughPort: 8443,
782+
}
783+
784+
mainCfgWithoutTLSPassthrough = MainConfig{
785+
ServerNamesHashMaxSize: "512",
786+
ServerTokens: "off",
787+
WorkerProcesses: "auto",
788+
WorkerCPUAffinity: "auto",
789+
WorkerShutdownTimeout: "1m",
790+
WorkerConnections: "1024",
791+
WorkerRlimitNofile: "65536",
792+
LogFormat: []string{"$remote_addr", "$remote_user"},
793+
LogFormatEscaping: "default",
794+
StreamSnippets: []string{"# comment"},
795+
StreamLogFormat: []string{"$remote_addr", "$remote_user"},
796+
StreamLogFormatEscaping: "none",
797+
ResolverAddresses: []string{"example.com", "127.0.0.1"},
798+
ResolverIPV6: false,
799+
ResolverValid: "10s",
800+
ResolverTimeout: "15s",
801+
KeepaliveTimeout: "65s",
802+
KeepaliveRequests: 100,
803+
VariablesHashBucketSize: 256,
804+
VariablesHashMaxSize: 1024,
805+
TLSPassthrough: false,
806+
TLSPassthroughPort: 8443,
600807
}
601808

602809
// Vars for Mergable Ingress Master - Minion tests

internal/configs/version1/templates_test.go

Whitespace-only changes.

0 commit comments

Comments
 (0)