Add more test coverage for Redis Checkpoint
This commit is contained in:
parent
6401371727
commit
b0245d688b
1 changed files with 23 additions and 21 deletions
|
|
@ -2,47 +2,49 @@ package redis
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gopkg.in/redis.v5"
|
||||
)
|
||||
|
||||
var defaultAddr = "127.0.0.1:6379"
|
||||
|
||||
func Test_CheckpointLifecycle(t *testing.T) {
|
||||
client := redis.NewClient(&redis.Options{Addr: defaultAddr})
|
||||
|
||||
c := &Checkpoint{
|
||||
appName: "app",
|
||||
client: client,
|
||||
// new
|
||||
c, err := New("app")
|
||||
if err != nil {
|
||||
t.Fatalf("new checkpoint error: %v", err)
|
||||
}
|
||||
|
||||
// set checkpoint
|
||||
// set
|
||||
c.Set("streamName", "shardID", "testSeqNum")
|
||||
|
||||
// get checkpoint
|
||||
// get
|
||||
val, err := c.Get("streamName", "shardID")
|
||||
if err != nil {
|
||||
t.Fatalf("get checkpoint error: %v", err)
|
||||
}
|
||||
|
||||
if val != "testSeqNum" {
|
||||
t.Fatalf("checkpoint exists expected %s, got %s", "testSeqNum", val)
|
||||
}
|
||||
}
|
||||
|
||||
client.Del(c.key("streamName", "shardID"))
|
||||
func Test_SetEmptySeqNum(t *testing.T) {
|
||||
c, err := New("app")
|
||||
if err != nil {
|
||||
t.Fatalf("new checkpoint error: %v", err)
|
||||
}
|
||||
|
||||
err = c.Set("streamName", "shardID", "")
|
||||
if err == nil {
|
||||
t.Fatalf("should not allow empty sequence number")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_key(t *testing.T) {
|
||||
client := redis.NewClient(&redis.Options{Addr: defaultAddr})
|
||||
|
||||
c := &Checkpoint{
|
||||
appName: "app",
|
||||
client: client,
|
||||
c, err := New("app")
|
||||
if err != nil {
|
||||
t.Fatalf("new checkpoint error: %v", err)
|
||||
}
|
||||
|
||||
expected := "app:checkpoint:stream:shard"
|
||||
want := "app:checkpoint:stream:shard"
|
||||
|
||||
if val := c.key("stream", "shard"); val != expected {
|
||||
t.Fatalf("checkpoint exists expected %s, got %s", expected, val)
|
||||
if got := c.key("stream", "shard"); got != want {
|
||||
t.Fatalf("checkpoint key, want %s, got %s", want, got)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue