-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodule_test.go
More file actions
74 lines (66 loc) · 1.8 KB
/
Copy pathmodule_test.go
File metadata and controls
74 lines (66 loc) · 1.8 KB
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
68
69
70
71
72
73
74
package autodns_test
import (
"fmt"
"testing"
caddyautodns "github.com/KlettIT/caddy-autodns"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/libdns/autodns"
"github.com/libdns/autodns/sdk"
)
func TestUnmarshalCaddyFile(t *testing.T) {
tests := []struct {
config string
expectedUser string
expectedPass string
expectedContext string
}{
{
config: `autodns {
username theusername
password secretpassword
}`,
expectedUser: "theusername",
expectedPass: "secretpassword",
expectedContext: "",
},
{
config: `autodns {
username someuser
password somepassword
context 123
}`,
expectedUser: "someuser",
expectedPass: "somepassword",
expectedContext: "123",
},
}
for i, tc := range tests {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
// given
dispenser := caddyfile.NewTestDispenser(tc.config)
p := caddyautodns.Provider{&autodns.Provider{Client: &sdk.SDK{}}}
// when
err := p.UnmarshalCaddyfile(dispenser)
// then
if err != nil {
t.Errorf("UnmarshalCaddyfile failed with %v", err)
return
}
if tc.expectedUser != p.Provider.Client.Username {
t.Errorf("Expected Username to be '%s' but got '%s'", tc.expectedUser, p.Provider.Client.Username)
}
if tc.expectedPass != p.Provider.Client.Password {
t.Errorf("Expected Password to be '%s' but got '%s'", tc.expectedPass, p.Provider.Client.Password)
}
if tc.expectedContext != "" {
if tc.expectedContext != p.Provider.Client.Context {
t.Errorf("Expected Context to be '%s' but got '%s'", tc.expectedContext, p.Provider.Client.Context)
}
} else {
if p.Provider.Client.Context != "" {
t.Errorf("Expected Context to be empty but got '%s'", p.Provider.Client.Context)
}
}
})
}
}