-
Notifications
You must be signed in to change notification settings - Fork 0
/
caddyfile_test.go
113 lines (102 loc) · 2.16 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
package caddylura
import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestParseCaddyFile(t *testing.T) {
input := `
lura {
timeout 10s
cache_ttl 360s
debug_endpoint /api/__debug
echo_endpoint
endpoint /users/{user} {
method GET
backend {
to http://mock:8081
url_pattern /registered/{user}
allow id name email
mapping {
email>personal_email
}
}
backend {
to http://mock:8081
url_pattern /users/{user}/permissions
group permissions
}
concurrent_calls 2
timeout 1000s
cache_ttl 3600s
}
endpoint {
url_pattern /foo/bar
method POST
backend http://mock:8082 http://mock:8083 {
url_pattern /baz
method PUT
}
}
}
`
d := caddyfile.NewTestDispenser(input)
l := new(Lura)
err := l.UnmarshalCaddyfile(d)
if !assert.NoError(t, err) {
t.Fatal()
}
expected := &Lura{
Timeout: caddy.Duration(10 * time.Second),
CacheTTL: caddy.Duration(360 * time.Second),
DebugEndpoint: HelperEndpoint{
URLPattern: "/api/__debug",
Enabled: true,
},
EchoEndpoint: HelperEndpoint{
URLPattern: "",
Enabled: true,
},
Endpoints: []Endpoint{
{
Method: "GET",
URLPattern: "/users/{user}",
Backends: []Backend{
{
Host: []string{"http://mock:8081"},
URLPattern: "/registered/{user}",
AllowList: []string{"id", "name", "email"},
Mapping: map[string]string{
"email": "personal_email",
},
},
{
Host: []string{"http://mock:8081"},
URLPattern: "/users/{user}/permissions",
Group: "permissions",
},
},
ConcurrentCalls: 2,
Timeout: caddy.Duration(1000 * time.Second),
CacheTTL: caddy.Duration(3600 * time.Second),
},
{
Method: "POST",
URLPattern: "/foo/bar",
Backends: []Backend{
{
Host: []string{
"http://mock:8082",
"http://mock:8083",
},
URLPattern: "/baz",
Method: "PUT",
},
},
},
},
}
assert.Equal(t, expected, l)
}