(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func TestGinJWTMiddleware_FunctionalOptions(t *testing.T) { |
| 117 | gin.SetMode(gin.TestMode) |
| 118 | |
| 119 | host, port := setupRedisContainerForJWT(t) |
| 120 | |
| 121 | redisAddr := fmt.Sprintf("%s:%s", host, port) |
| 122 | |
| 123 | t.Run("EnableRedisStoreDefault", func(t *testing.T) { |
| 124 | middleware := &GinJWTMiddleware{ |
| 125 | Realm: "test zone", |
| 126 | Key: []byte("secret key"), |
| 127 | Timeout: time.Hour, |
| 128 | MaxRefresh: time.Hour * 24, |
| 129 | IdentityKey: "id", |
| 130 | } |
| 131 | |
| 132 | // Test EnableRedisStore with no options (default) |
| 133 | result := middleware.EnableRedisStore() |
| 134 | assert.Equal(t, middleware, result, "should return self for chaining") |
| 135 | assert.True(t, middleware.UseRedisStore, "should enable Redis store") |
| 136 | assert.NotNil(t, middleware.RedisConfig, "should set default Redis config") |
| 137 | assert.Equal(t, "localhost:6379", middleware.RedisConfig.Addr, "should use default address") |
| 138 | }) |
| 139 | |
| 140 | t.Run("EnableRedisStoreWithAddr", func(t *testing.T) { |
| 141 | middleware := &GinJWTMiddleware{ |
| 142 | Realm: "test zone", |
| 143 | Key: []byte("secret key"), |
| 144 | Timeout: time.Hour, |
| 145 | MaxRefresh: time.Hour * 24, |
| 146 | IdentityKey: "id", |
| 147 | } |
| 148 | |
| 149 | // Test EnableRedisStore with address option |
| 150 | result := middleware.EnableRedisStore(WithRedisAddr(redisAddr)) |
| 151 | assert.Equal(t, middleware, result, "should return self for chaining") |
| 152 | assert.True(t, middleware.UseRedisStore, "should enable Redis store") |
| 153 | assert.Equal(t, redisAddr, middleware.RedisConfig.Addr, "should set custom address") |
| 154 | }) |
| 155 | |
| 156 | t.Run("EnableRedisStoreWithAuth", func(t *testing.T) { |
| 157 | middleware := &GinJWTMiddleware{ |
| 158 | Realm: "test zone", |
| 159 | Key: []byte("secret key"), |
| 160 | Timeout: time.Hour, |
| 161 | MaxRefresh: time.Hour * 24, |
| 162 | IdentityKey: "id", |
| 163 | } |
| 164 | |
| 165 | // Test EnableRedisStore with auth options |
| 166 | result := middleware.EnableRedisStore( |
| 167 | WithRedisAddr(redisAddr), |
| 168 | WithRedisAuth("testpass", 1), |
| 169 | ) |
| 170 | assert.Equal(t, middleware, result, "should return self for chaining") |
| 171 | assert.True(t, middleware.UseRedisStore, "should enable Redis store") |
| 172 | assert.Equal(t, redisAddr, middleware.RedisConfig.Addr, "should set custom address") |
| 173 | assert.Equal(t, "testpass", middleware.RedisConfig.Password, "should set custom password") |
nothing calls this directly
no test coverage detected
searching dependent graphs…