forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmw_redis_cache_test.go
50 lines (39 loc) · 1.2 KB
/
mw_redis_cache_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
package gateway
import (
"testing"
"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/test"
)
func TestRedisCacheMiddleware_WithCompressedResponse(t *testing.T) {
const path = "/compressed"
globalConf := config.Global()
globalConf.AnalyticsConfig.EnableDetailedRecording = true
config.SetGlobal(globalConf)
ts := StartTest()
defer ts.Close()
createAPI := func(withCache bool) {
BuildAndLoadAPI(func(spec *APISpec) {
spec.Proxy.ListenPath = "/"
spec.CacheOptions.CacheTimeout = 60
spec.CacheOptions.EnableCache = withCache
UpdateAPIVersion(spec, "v1", func(v *apidef.VersionInfo) {
v.ExtendedPaths.Cached = []string{path}
})
})
}
t.Run("without cache", func(t *testing.T) {
createAPI(false)
ts.Run(t, []test.TestCase{
{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
}...)
})
t.Run("with cache", func(t *testing.T) {
createAPI(true)
ts.Run(t, []test.TestCase{
{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
}...)
})
}