(t *testing.T)
| 194 | } |
| 195 | |
| 196 | func TestExpireStructure_PEXPIREBY(t *testing.T) { |
| 197 | expire, _ := initExpire() |
| 198 | defer expire.db.Close() |
| 199 | |
| 200 | key := "test_key" |
| 201 | duration := int64(2000) |
| 202 | |
| 203 | // Test PEXPIREBY function without tag |
| 204 | expireErr = expire.PEXPIREBY(key, duration) |
| 205 | assert.Nil(t, expireErr) |
| 206 | |
| 207 | // Wait for the key to expire |
| 208 | time.Sleep(time.Millisecond * time.Duration(duration+100)) |
| 209 | |
| 210 | // Check if the key has expired |
| 211 | ttl, err := expire.TTL(key) |
| 212 | assert.Nil(t, err) |
| 213 | assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist |
| 214 | |
| 215 | // Test PEXPIREBY function with tag "ex" |
| 216 | expireErr = expire.PEXPIREBY(key, duration, "ex") |
| 217 | assert.Nil(t, expireErr) |
| 218 | |
| 219 | // Wait for the key to expire |
| 220 | time.Sleep(time.Millisecond * time.Duration(duration+100)) |
| 221 | |
| 222 | // Check if the key has expired |
| 223 | ttl, err = expire.TTL(key) |
| 224 | assert.Nil(t, err) |
| 225 | assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist |
| 226 | |
| 227 | // Test PEXPIREBY function with an invalid tag |
| 228 | expireErr = expire.PEXPIREBY(key, duration, "invalid_tag") |
| 229 | assert.Equal(t, ErrInvalidArgs, expireErr) |
| 230 | } |
| 231 | |
| 232 | func TestExpireStructure_EXPIREBYAT(t *testing.T) { |
| 233 | expire, _ := initExpire() |
nothing calls this directly
no test coverage detected