mirror of
https://github.com/jwhited/wgsd.git
synced 2025-01-18 22:09:34 +08:00
add setup() tests
This commit is contained in:
parent
eacaffd0e3
commit
1c759627ec
2
setup.go
2
setup.go
@ -37,7 +37,7 @@ func setup(c *caddy.Controller) error {
|
|||||||
client, err := wgctrl.New()
|
client, err := wgctrl.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return plugin.Error("wgsd",
|
return plugin.Error("wgsd",
|
||||||
fmt.Errorf("wgsd: error constructing wgctrl client: %v",
|
fmt.Errorf("error constructing wgctrl client: %v",
|
||||||
err))
|
err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
41
setup_test.go
Normal file
41
setup_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package wgsd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/caddyserver/caddy"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSetup(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
expectErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"valid input",
|
||||||
|
"wgsd example.com. wg0",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"missing token",
|
||||||
|
"wgsd example.com.",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"too many tokens",
|
||||||
|
"wgsd example.com. wg0 extra",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user