-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbunny_test.go
62 lines (53 loc) · 1.15 KB
/
bunny_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
package bunny
import (
"fmt"
"os"
"testing"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/libdns/bunny"
)
type testCase struct {
input string
setenv string
expect string
}
func TestUnmarshalCaddyFile(t *testing.T) {
tests := []testCase{
{
input: `bunny {
access_key A123
}`,
expect: "A123",
}, {
input: `bunny {
access_key {env.BUNNY_ACCESS_KEY}
}`,
setenv: "321",
expect: "321",
}, {
input: `bunny 123`,
expect: "123",
},
}
for i, tc := range tests {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
dispenser := caddyfile.NewTestDispenser(tc.input)
p := Provider{Provider: &bunny.Provider{}}
err := p.UnmarshalCaddyfile(dispenser)
if err != nil {
t.Errorf("UnmarshalCaddyfile failed with %v", err)
return
}
os.Setenv("BUNNY_ACCESS_KEY", tc.setenv)
err = p.Provision(caddy.Context{})
if err != nil {
t.Errorf("Provision failed with %v", err)
return
}
if tc.expect != p.Provider.AccessKey {
t.Errorf("Expected AccessKey to be '%s' but got '%s'", tc.expect, p.Provider.AccessKey)
}
})
}
}