jwhited-wgsd/setup_test.go

99 lines
1.5 KiB
Go
Raw Normal View History

2020-05-27 13:03:24 -07:00
package wgsd
import (
"testing"
"github.com/coredns/caddy"
2020-05-27 13:03:24 -07:00
)
func TestSetup(t *testing.T) {
testCases := []struct {
name string
input string
expectErr bool
expectSelfAllowedIPs []string
expectSelfEndpoint []string
2020-05-27 13:03:24 -07:00
}{
{
"valid input",
"wgsd example.com. wg0",
false,
nil,
nil,
2020-05-27 13:03:24 -07:00
},
{
"missing token",
"wgsd example.com.",
true,
nil,
nil,
2020-05-27 13:03:24 -07:00
},
{
"too many tokens",
"wgsd example.com. wg0 extra",
true,
nil,
nil,
},
{
"valid self-allowed-ips",
`wgsd example.com. wg0 {
self-allowed-ips 10.0.0.1/32 10.0.0.2/32
}`,
false,
nil,
nil,
},
{
"invalid self-allowed-ips",
`wgsd example.com. wg0 {
self-allowed-ips 10.0.01/32 10.0.0.2/32
}`,
true,
nil,
nil,
},
{
"valid self-endpoint",
`wgsd example.com. wg0 {
self-endpoint 127.0.0.1:51820
}`,
false,
nil,
nil,
},
{
"invalid self-endpoint",
`wgsd example.com. wg0 {
self-endpoint hostname:51820
}`,
true,
nil,
nil,
},
{
"all options",
`wgsd example.com. wg0 {
self-allowed-ips 10.0.0.1/32 10.0.0.2/32
self-endpoint 127.0.0.1:51820
}`,
false,
nil,
nil,
2020-05-27 13:03:24 -07:00
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
c := caddy.NewTestController("dns", tc.input)
err := setup(c)
if (err != nil) != tc.expectErr {
t.Fatalf("expectErr: %v, got err=%v", tc.expectErr, err)
}
if tc.expectErr {
return
}
2020-05-27 13:03:24 -07:00
})
}
}