-
Notifications
You must be signed in to change notification settings - Fork 2
/
caddyfile_test.go
135 lines (125 loc) · 2.82 KB
/
caddyfile_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package caddydiscord
import (
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/google/go-cmp/cmp"
"strings"
"testing"
)
var (
spaceReplacer = strings.NewReplacer(" ", "", "\r", "", "\n", "", "\t", "")
WithoutSpaces = cmp.Transformer("SpacesIgnored", func(in string) string {
return spaceReplacer.Replace(in)
})
)
func TestParsingGlobalOptions(t *testing.T) {
testcases := []struct {
name string
dispenser *caddyfile.Dispenser
want string
}{
{
name: "all discord users",
dispenser: caddyfile.NewTestDispenser(`{
discord {
client_id 1000000000000005
client_secret 7SEWAAAA1AP_k
redirect http://localhost:8080/discord/callback
realm really_cool_area {
*
}
}
}`),
want: `{
"clientID":"1000000000000005",
"clientSecret":"7SEWAAAA1AP_k",
"redirectURL":"http://localhost:8080/discord/callback",
"realms":[
{
"Ref":"really_cool_area",
"Identifiers": [
{"Resource":4,"Wildcard":true}
]
}
]
}`,
},
{
name: "guild members only",
dispenser: caddyfile.NewTestDispenser(`{
discord {
client_id 1000000000000005
client_secret 7SEWAAAA1AP_k
redirect http://localhost:8080/discord/callback
realm nice_guild {
guild 12354 {
*
}
}
}
}`),
want: `{
"clientID":"1000000000000005",
"clientSecret":"7SEWAAAA1AP_k",
"redirectURL":"http://localhost:8080/discord/callback",
"realms":[
{
"Ref":"nice_guild",
"Identifiers": [
{"Resource":1,"GuildID":"12354","Wildcard":true}
]
}
]
}`,
},
{
name: "explicit user id and everyone on discord",
dispenser: caddyfile.NewTestDispenser(`{
discord {
client_id 1000000000000005
client_secret 7SEWAAAA1AP_k
redirect http://localhost:8080/discord/callback
realm really_cool_area {
user 314009365487026176
}
realm nice_guild {
guild 679814978257027100 {
*
}
}
}
}`),
want: `{
"clientID":"1000000000000005",
"clientSecret":"7SEWAAAA1AP_k",
"redirectURL":"http://localhost:8080/discord/callback",
"realms":[
{
"Ref":"really_cool_area",
"Identifiers": [
{"Resource":4,"Identifier":"314009365487026176"}
]
},
{
"Ref":"nice_guild",
"Identifiers": [
{"Resource":1,"GuildID":"679814978257027100","Wildcard":true}
]
}
]
}`,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
app, err := parseCaddyfileGlobalOption(tc.dispenser, nil)
if err != nil {
t.Fail()
}
got := string(app.(httpcaddyfile.App).Value)
if diff := cmp.Diff(tc.want, got, WithoutSpaces); diff != "" {
t.Error(diff)
}
})
}
}