mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
c8557dc00b
* caddyfile: Introduce basic linting and fmt check This will help encourage people to keep their Caddyfiles tidy. * Remove unrelated tests I am not sure that testing the output of warnings here is quite the right idea; these tests are just for syntax and parsing success.
54 lines
831 B
Go
54 lines
831 B
Go
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
|
|
expectError bool
|
|
}{
|
|
{
|
|
input: `:8080 {
|
|
log
|
|
}
|
|
`,
|
|
expectError: false,
|
|
},
|
|
{
|
|
input: `:8080 {
|
|
log {
|
|
output file foo.log
|
|
}
|
|
}
|
|
`,
|
|
expectError: false,
|
|
},
|
|
{
|
|
input: `:8080 {
|
|
log /foo {
|
|
output file foo.log
|
|
}
|
|
}
|
|
`,
|
|
expectError: true,
|
|
},
|
|
} {
|
|
|
|
adapter := caddyfile.Adapter{
|
|
ServerType: ServerType{},
|
|
}
|
|
|
|
_, _, err := adapter.Adapt([]byte(tc.input), nil)
|
|
|
|
if err != nil != tc.expectError {
|
|
t.Errorf("Test %d error expectation failed Expected: %v, got %s", i, tc.expectError, err)
|
|
continue
|
|
}
|
|
}
|
|
}
|