-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextraheaders_test.go
47 lines (36 loc) · 1 KB
/
extraheaders_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
package traefik_extraheaders_test
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
extraheaders "github.com/mrambossek/traefik-extraheaders"
)
func TestExtraheaders(t *testing.T) {
cfg := extraheaders.CreateConfig()
cfg.ClientPortHeader = "Test-Forwarded-Clientport"
cfg.HTTPVerHeader = "Test-Forwarded-HTTP-Ver"
ctx := context.Background()
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
handler, err := extraheaders.New(ctx, next, cfg, "demo-plugin")
if err != nil {
t.Fatal(err)
}
recorder := httptest.NewRecorder()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost", nil)
if err != nil {
t.Fatal(err)
}
handler.ServeHTTP(recorder, req)
fmt.Printf("req = %v", req)
// assertHeader(t, req, "X-Extraheaders", "test")
}
/*
func assertHeader(t *testing.T, req *http.Request, key, expected string) {
t.Helper()
if req.Header.Get(key) != expected {
t.Errorf("invalid header value: %s", req.Header.Get(key))
}
}
*/