caddy/caddyconfig/httpcaddyfile/builtins_test.go

63 lines
1.1 KiB
Go
Raw Normal View History

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
}
}
}