-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrylist_test.go
58 lines (50 loc) · 1.63 KB
/
entrylist_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
package baker_test
import (
"fmt"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"ella.to/baker"
"ella.to/baker/rule"
)
func TestBakerEndpoints(t *testing.T) {
{
rr := httptest.NewRecorder()
baker.NewEntryList().
New("example.com", "/", true).
WriteResponse(rr)
assert.JSONEq(t, `{"endpoints":[{"domain":"example.com","path":"/","rules":[]}]}`, strings.TrimSpace(rr.Body.String()))
}
{
rr := httptest.NewRecorder()
baker.NewEntryList().
New("example.com", "/", true).
WithRules(rule.NewAppendPath("a", "b")).
WriteResponse(rr)
assert.JSONEq(t, `{"endpoints":[{"domain":"example.com","path":"/","rules":[{"args":{"begin":"a","end":"b"},"type":"AppendPath"}]}]}`, strings.TrimSpace(rr.Body.String()))
}
{
rr := httptest.NewRecorder()
baker.NewEntryList().
New("example.com", "/", true).
WithRules(
rule.NewAppendPath("a", "b"),
rule.NewReplacePath("/a", "/b", 1),
).
WriteResponse(rr)
assert.JSONEq(t, `{"endpoints":[{"domain":"example.com","path":"/","rules":[{"args":{"begin":"a","end":"b"},"type":"AppendPath"},{"args":{"search":"/a","replace":"/b","times":1},"type":"ReplacePath"}]}]}`, strings.TrimSpace(rr.Body.String()))
}
{
rr := httptest.NewRecorder()
baker.NewEntryList().
New("example.com", "/", true).
WithRules(
rule.NewRateLimiter(1, 1*time.Second),
).
WriteResponse(rr)
fmt.Println(strings.TrimSpace(rr.Body.String()))
assert.JSONEq(t, `{"endpoints":[{"domain":"example.com","path":"/","rules":[{"type":"RateLimiter","args":{"request_limit":1,"window_duration":"1s"}}]}]}`, strings.TrimSpace(rr.Body.String()))
}
}