(t *testing.T)
| 158 | } |
| 159 | |
| 160 | func TestExpireStructure_EXPIREBY(t *testing.T) { |
| 161 | expire, _ := initExpire() |
| 162 | defer expire.db.Close() |
| 163 | |
| 164 | key := "test_key" |
| 165 | duration := int64(2) |
| 166 | |
| 167 | // Test EXPIREBY function without tag |
| 168 | expireErr = expire.EXPIREBY(key, duration) |
| 169 | assert.Nil(t, expireErr) |
| 170 | |
| 171 | // Wait for the key to expire |
| 172 | time.Sleep(time.Second * time.Duration(duration+1)) |
| 173 | |
| 174 | // Check if the key has expired |
| 175 | ttl, err := expire.TTL(key) |
| 176 | assert.Nil(t, err) |
| 177 | assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist |
| 178 | |
| 179 | // Test EXPIREBY function with tag "ex" |
| 180 | expireErr = expire.EXPIREBY(key, duration, "ex") |
| 181 | assert.Nil(t, expireErr) |
| 182 | |
| 183 | // Wait for the key to expire |
| 184 | time.Sleep(time.Second * time.Duration(duration+1)) |
| 185 | |
| 186 | // Check if the key has expired |
| 187 | ttl, err = expire.TTL(key) |
| 188 | assert.Nil(t, err) |
| 189 | assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist |
| 190 | |
| 191 | // Test EXPIREBY function with an invalid tag |
| 192 | expireErr = expire.EXPIREBY(key, duration, "invalid_tag") |
| 193 | assert.Equal(t, ErrInvalidArgs, expireErr) |
| 194 | } |
| 195 | |
| 196 | func TestExpireStructure_PEXPIREBY(t *testing.T) { |
| 197 | expire, _ := initExpire() |
nothing calls this directly
no test coverage detected