forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmw_context_vars_test.go
36 lines (31 loc) · 959 Bytes
/
mw_context_vars_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
package main
import (
"testing"
"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/test"
)
func TestContextVarsMiddleware(t *testing.T) {
ts := newTykTestServer()
defer ts.Close()
buildAndLoadAPI(func(spec *APISpec) {
spec.Proxy.ListenPath = "/"
spec.EnableContextVars = true
spec.VersionData.Versions = map[string]apidef.VersionInfo{
"v1": {
UseExtendedPaths: true,
GlobalHeaders: map[string]string{
"X-Static": "foo",
"X-Request-ID": "$tyk_context.request_id",
"X-Path": "$tyk_context.path",
"X-Remote-Addr": "$tyk_context.remote_addr",
},
},
}
})
ts.Run(t, []test.TestCase{
{Path: "/test/path", Code: 200, BodyMatch: `"X-Remote-Addr":"127.0.0.1"`},
{Path: "/test/path", Code: 200, BodyMatch: `"X-Path":"/test/path"`},
{Path: "/test/path", Code: 200, BodyMatch: `"X-Static":"foo"`},
{Path: "/test/path", Code: 200, BodyMatch: `"X-Request-Id":"`},
}...)
}