-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_test.go
67 lines (60 loc) · 1.45 KB
/
setup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package dnsimple
import (
"context"
"testing"
"github.com/coredns/caddy"
"github.com/stretchr/testify/assert"
)
func TestSetupDNSimple(t *testing.T) {
t.Setenv("DNSIMPLE_TOKEN", "token")
t.Setenv("DNSIMPLE_ACCOUNT_ID", "12345")
fakeClient := new(fakeDNSimpleClient)
newDnsimpleService = func(ctx context.Context, options Options, accessToken, baseUrl string) (dnsimpleService, error) {
return fakeClient, nil
}
tests := []struct {
body string
expectedError bool
}{
{`dnsimple`, true},
{`dnsimple :`, true},
{`dnsimple ::`, true},
{`dnsimple example.org`, false},
{`dnsimple example.org:`, false},
{`dnsimple example.org.`, false},
{`dnsimple example.org:AMS { }`, false},
{`dnsimple example.org {
access_token
}`, true},
{`dnsimple example.org {
account_id 12345
}`, false},
{`dnsimple example.org {
base_url https://api.dnsimple.com/
}`, false},
{`dnsimple example.org {
identifier example
}`, false},
{`dnsimple example.org {
max_retries 10
}`, false},
{`dnsimple example.org {
refresh 1h
}`, false},
{`dnsimple example.org {
refresh 2s
}`, false},
{`dnsimple example.org {
wat
}`, true},
}
for _, test := range tests {
c := caddy.NewTestController("dns", test.body)
err := setup(c)
if test.expectedError {
assert.Error(t, err, "Expected error for %s, but got none", test.body)
} else {
assert.NoError(t, err, "Unexpected error occurred for %s", test.body)
}
}
}