package redis

import (
	"testing"
)

func Test_CheckpointLifecycle(t *testing.T) {
	// new
	c, err := New("app")
	if err != nil {
		t.Fatalf("new checkpoint error: %v", err)
	}

	// set
	c.Set("streamName", "shardID", "testSeqNum")

	// 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)
	}
}

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) {
	c, err := New("app")
	if err != nil {
		t.Fatalf("new checkpoint error: %v", err)
	}

	want := "app:checkpoint:stream:shard"

	if got := c.key("stream", "shard"); got != want {
		t.Fatalf("checkpoint key, want %s, got %s", want, got)
	}
}

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,
	}

	// set checkpoint
	c.Set("streamName", "shardID", "testSeqNum")

	// get checkpoint
	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_key(t *testing.T) {
	client := redis.NewClient(&redis.Options{Addr: defaultAddr})

	c := &Checkpoint{
		appName: "app",
		client:  client,
	}

	expected := "app:checkpoint:stream:shard"

	if val := c.key("stream", "shard"); val != expected {
		t.Fatalf("checkpoint exists expected %s, got %s", expected, val)
	}
}

--- 
+++ 
@@ -2,47 +2,49 @@
 
 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)
 	}
 }
Add more test coverage for Redis Checkpoint
