-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaeb_test.go
44 lines (33 loc) · 1.01 KB
/
waeb_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
package traefik_plugin_waeb_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
waeb "github.com/tomMoulard/traefik-plugin-waeb"
)
func TestWaeb(t *testing.T) {
t.Parallel()
cfg := waeb.CreateConfig()
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
// Should NEVER go through the next handler
t.Fail()
})
handler, err := waeb.New(context.Background(), next, cfg, "waeb")
if err != nil {
t.Fatal(err)
}
recorder := httptest.NewRecorder()
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://localhost/waeb.go", nil)
if err != nil {
t.Fatal(err)
}
handler.ServeHTTP(recorder, req)
if recorder.Code != http.StatusOK {
t.Errorf("invalid recorder status code, expected: %d, got: %d", http.StatusOK, recorder.Code)
}
if recorder.Header().Get("Content-Type") != "text/x-go; charset=utf-8" {
t.Errorf("invalid Content-Type, expected: %q, got: %q",
"text/x-go; charset=utf-8", recorder.Header().Get("Content-Type"))
}
}