MCPcopy
hub / github.com/appleboy/gin-jwt / TestGinJWTMiddleware_FunctionalOptionsOnly

Function TestGinJWTMiddleware_FunctionalOptionsOnly

auth_jwt_methods_test.go:11–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestGinJWTMiddleware_FunctionalOptionsOnly(t *testing.T) {
12 gin.SetMode(gin.TestMode)
13
14 t.Run("EnableRedisStoreDefault", func(t *testing.T) {
15 middleware := &GinJWTMiddleware{
16 Realm: "test zone",
17 Key: []byte("secret key"),
18 Timeout: time.Hour,
19 MaxRefresh: time.Hour * 24,
20 IdentityKey: "id",
21 }
22
23 // Test EnableRedisStore with no options (default)
24 result := middleware.EnableRedisStore()
25 assert.Equal(t, middleware, result, "should return self for chaining")
26 assert.True(t, middleware.UseRedisStore, "should enable Redis store")
27 assert.NotNil(t, middleware.RedisConfig, "should set default Redis config")
28 assert.Equal(t, "localhost:6379", middleware.RedisConfig.Addr, "should set default address")
29 })
30
31 t.Run("EnableRedisStoreWithSingleOption", func(t *testing.T) {
32 middleware := &GinJWTMiddleware{
33 Realm: "test zone",
34 Key: []byte("secret key"),
35 Timeout: time.Hour,
36 MaxRefresh: time.Hour * 24,
37 IdentityKey: "id",
38 }
39
40 testAddr := "redis.example.com:6379"
41
42 // Test EnableRedisStore with single option
43 result := middleware.EnableRedisStore(WithRedisAddr(testAddr))
44 assert.Equal(t, middleware, result, "should return self for chaining")
45 assert.True(t, middleware.UseRedisStore, "should enable Redis store")
46 assert.Equal(t, testAddr, middleware.RedisConfig.Addr, "should set custom address")
47 // Should still have defaults for other values
48 assert.Equal(t, "", middleware.RedisConfig.Password, "should have default empty password")
49 assert.Equal(t, 0, middleware.RedisConfig.DB, "should have default DB")
50 })
51
52 t.Run("EnableRedisStoreWithMultipleOptions", func(t *testing.T) {
53 middleware := &GinJWTMiddleware{
54 Realm: "test zone",
55 Key: []byte("secret key"),
56 Timeout: time.Hour,
57 MaxRefresh: time.Hour * 24,
58 IdentityKey: "id",
59 }
60
61 testAddr := "redis.example.com:6379"
62 testPassword := "testpass"
63 testDB := 5
64
65 // Test EnableRedisStore with multiple options
66 result := middleware.EnableRedisStore(
67 WithRedisAddr(testAddr),
68 WithRedisAuth(testPassword, testDB),

Callers

nothing calls this directly

Calls 6

EnableRedisStoreMethod · 0.95
WithRedisAddrFunction · 0.85
WithRedisAuthFunction · 0.85
WithRedisCacheFunction · 0.85
WithRedisPoolFunction · 0.85
WithRedisKeyPrefixFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…