redisTs_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2021-2022 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //go:build redisdb || !core
  15. package redis
  16. import (
  17. "testing"
  18. "github.com/alicebob/miniredis/v2"
  19. "github.com/redis/go-redis/v9"
  20. "github.com/lf-edge/ekuiper/internal/pkg/store/test/common"
  21. ts2 "github.com/lf-edge/ekuiper/pkg/kv"
  22. )
  23. func TestRedisTsSet(t *testing.T) {
  24. ks, db, minRedis := setupTRedisKv()
  25. defer cleanRedisKv(db, minRedis)
  26. common.TestTsSet(ks, t)
  27. }
  28. func TestRedisTsLast(t *testing.T) {
  29. ks, db, minRedis := setupTRedisKv()
  30. defer cleanRedisKv(db, minRedis)
  31. common.TestTsLast(ks, t)
  32. }
  33. func TestRedisTsGet(t *testing.T) {
  34. ks, db, minRedis := setupTRedisKv()
  35. defer cleanRedisKv(db, minRedis)
  36. common.TestTsGet(ks, t)
  37. }
  38. func TestRedisTsDelete(t *testing.T) {
  39. ks, db, minRedis := setupTRedisKv()
  40. defer cleanRedisKv(db, minRedis)
  41. common.TestTsDelete(ks, t)
  42. }
  43. func TestRedisTsDeleteBefore(t *testing.T) {
  44. ks, db, minRedis := setupTRedisKv()
  45. defer cleanRedisKv(db, minRedis)
  46. common.TestTsDeleteBefore(ks, t)
  47. }
  48. func setupTRedisKv() (ts2.Tskv, *redis.Client, *miniredis.Miniredis) {
  49. minRedis, err := miniredis.Run()
  50. if err != nil {
  51. panic(err)
  52. }
  53. redisDB := redis.NewClient(&redis.Options{
  54. Addr: minRedis.Addr(),
  55. })
  56. builder := NewTsBuilder(redisDB)
  57. var ks ts2.Tskv
  58. ks, err = builder.CreateTs("test")
  59. if err != nil {
  60. panic(err)
  61. }
  62. return ks, redisDB, minRedis
  63. }