From 21de227fe94508d0e259dfd803b482055b214640 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Fri, 15 May 2020 17:57:16 -0400 Subject: httpcaddyfile: Be stricter about `log` syntax (#3419) --- caddyconfig/httpcaddyfile/builtins_test.go | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 caddyconfig/httpcaddyfile/builtins_test.go (limited to 'caddyconfig/httpcaddyfile/builtins_test.go') diff --git a/caddyconfig/httpcaddyfile/builtins_test.go b/caddyconfig/httpcaddyfile/builtins_test.go new file mode 100644 index 0000000..a255538 --- /dev/null +++ b/caddyconfig/httpcaddyfile/builtins_test.go @@ -0,0 +1,62 @@ +package httpcaddyfile + +import ( + "testing" + + "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" + _ "github.com/caddyserver/caddy/v2/modules/logging" +) + +func TestLogDirectiveSyntax(t *testing.T) { + for i, tc := range []struct { + input string + expectWarn bool + expectError bool + }{ + { + input: `:8080 { + log + } + `, + expectWarn: false, + expectError: false, + }, + { + input: `:8080 { + log { + output file foo.log + } + } + `, + expectWarn: false, + expectError: false, + }, + { + input: `:8080 { + log /foo { + output file foo.log + } + } + `, + expectWarn: false, + expectError: true, + }, + } { + + adapter := caddyfile.Adapter{ + ServerType: ServerType{}, + } + + _, warnings, err := adapter.Adapt([]byte(tc.input), nil) + + if len(warnings) > 0 != tc.expectWarn { + t.Errorf("Test %d warning expectation failed Expected: %v, got %v", i, tc.expectWarn, warnings) + continue + } + + if err != nil != tc.expectError { + t.Errorf("Test %d error expectation failed Expected: %v, got %s", i, tc.expectError, err) + continue + } + } +} -- cgit v1.2.3