mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-30 19:55:04 -04:00
parent
2762f8f058
commit
90f1f7bce7
@ -79,3 +79,71 @@ func TestSpecificity(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGlobalOptions(t *testing.T) {
|
||||||
|
for i, tc := range []struct {
|
||||||
|
input string
|
||||||
|
expectWarn bool
|
||||||
|
expectError bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: `
|
||||||
|
{
|
||||||
|
email test@example.com
|
||||||
|
}
|
||||||
|
:80
|
||||||
|
`,
|
||||||
|
expectWarn: false,
|
||||||
|
expectError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: `
|
||||||
|
{
|
||||||
|
admin off
|
||||||
|
}
|
||||||
|
:80
|
||||||
|
`,
|
||||||
|
expectWarn: false,
|
||||||
|
expectError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: `
|
||||||
|
{
|
||||||
|
admin 127.0.0.1:2020
|
||||||
|
}
|
||||||
|
:80
|
||||||
|
`,
|
||||||
|
expectWarn: false,
|
||||||
|
expectError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: `
|
||||||
|
{
|
||||||
|
admin {
|
||||||
|
disabled false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
:80
|
||||||
|
`,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -177,7 +177,9 @@ func parseOptSingleString(d *caddyfile.Dispenser) (string, error) {
|
|||||||
func parseOptAdmin(d *caddyfile.Dispenser) (string, error) {
|
func parseOptAdmin(d *caddyfile.Dispenser) (string, error) {
|
||||||
if d.Next() {
|
if d.Next() {
|
||||||
var listenAddress string
|
var listenAddress string
|
||||||
d.AllArgs(&listenAddress)
|
if !d.AllArgs(&listenAddress) {
|
||||||
|
return "", d.ArgErr()
|
||||||
|
}
|
||||||
if listenAddress == "" {
|
if listenAddress == "" {
|
||||||
listenAddress = caddy.DefaultAdminListen
|
listenAddress = caddy.DefaultAdminListen
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user