forked from greenpau/caddy-trace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaddyfile_test.go
49 lines (42 loc) · 1.15 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
package debug
import (
"net/http"
"net/url"
"testing"
"github.com/caddyserver/caddy/v2/caddytest"
)
func TestCaddyfile(t *testing.T) {
baseURL := "http://localhost:9080"
localhost, _ := url.Parse(baseURL)
tester := caddytest.NewTester(t)
tester.InitServer(`
{
http_port 9080
https_port 9443
}
localhost:9080 {
route {
trace disabled=yes
trace disabled=no tag="foo"
trace disabled=no tag="bar"
respond /version "1.0.0" 200
trace tag="marvel" response_debug=yes
trace tag="custom" response_debug=yes uri_filter="^/whoami$"
respond /whoami* 200 {
body "greenpau"
}
}
}
`, "caddyfile")
tester.AssertGetResponse(baseURL+"/version", 200, "1.0.0")
tester.AssertGetResponse(baseURL+"/whoami", 200, "greenpau")
cookies := []*http.Cookie{}
cookie := &http.Cookie{
Name: "access_code",
Value: "anonymous",
}
cookies = append(cookies, cookie)
tester.Client.Jar.SetCookies(localhost, cookies)
tester.AssertGetResponse(baseURL+"/whoami", 200, "greenpau")
tester.AssertGetResponse(baseURL+"/whoami?user=greenpau&mode=raw", 200, "greenpau")
}