github.com/anuvu/tyk@v2.9.0-beta9-dl-apic+incompatible/gateway/mw_redis_cache_test.go (about)

     1  package gateway
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/TykTechnologies/tyk/apidef"
     7  	"github.com/TykTechnologies/tyk/config"
     8  	"github.com/TykTechnologies/tyk/test"
     9  )
    10  
    11  func TestRedisCacheMiddleware_WithCompressedResponse(t *testing.T) {
    12  	const path = "/compressed"
    13  
    14  	globalConf := config.Global()
    15  	globalConf.AnalyticsConfig.EnableDetailedRecording = true
    16  	config.SetGlobal(globalConf)
    17  
    18  	ts := StartTest()
    19  	defer ts.Close()
    20  
    21  	createAPI := func(withCache bool) {
    22  		BuildAndLoadAPI(func(spec *APISpec) {
    23  			spec.Proxy.ListenPath = "/"
    24  			spec.CacheOptions.CacheTimeout = 60
    25  			spec.CacheOptions.EnableCache = withCache
    26  			UpdateAPIVersion(spec, "v1", func(v *apidef.VersionInfo) {
    27  				v.ExtendedPaths.Cached = []string{path}
    28  			})
    29  		})
    30  	}
    31  
    32  	t.Run("without cache", func(t *testing.T) {
    33  		createAPI(false)
    34  
    35  		ts.Run(t, []test.TestCase{
    36  			{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
    37  			{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
    38  		}...)
    39  	})
    40  
    41  	t.Run("with cache", func(t *testing.T) {
    42  		createAPI(true)
    43  
    44  		ts.Run(t, []test.TestCase{
    45  			{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
    46  			{Path: path, Code: 200, BodyMatch: "This is a compressed response"},
    47  		}...)
    48  	})
    49  
    50  }