diff --git a/couchbase/metadata.go b/couchbase/metadata.go index 1eeff37..c60b2a9 100644 --- a/couchbase/metadata.go +++ b/couchbase/metadata.go @@ -3,7 +3,9 @@ package couchbase import ( "context" "errors" + "github.com/couchbase/gocbcore/v10" "strconv" + "strings" "sync" "github.com/Trendyol/go-dcp/wrapper" @@ -19,7 +21,6 @@ import ( "github.com/json-iterator/go" - "github.com/couchbase/gocbcore/v10" "github.com/couchbase/gocbcore/v10/memd" ) @@ -147,5 +148,8 @@ func NewCBMetadata(client Client, config *config.Dcp) metadata.Metadata { func getCheckpointID(vbID uint16, groupName string) []byte { // _connector:cbgo:groupName:stdout-listener:checkpoint:vbId + if strings.Contains(groupName, ".") { + panic("can not get checkpoint id. unsupported group name includes dot") + } return []byte(helpers.Prefix + groupName + ":checkpoint:" + strconv.Itoa(int(vbID))) } diff --git a/couchbase/metedata_test.go b/couchbase/metedata_test.go new file mode 100644 index 0000000..963c8f1 --- /dev/null +++ b/couchbase/metedata_test.go @@ -0,0 +1,24 @@ +package couchbase + +import ( + "bytes" + "testing" +) + +func TestGetCheckpointID(t *testing.T) { + expected := []byte("_connector:cbgo:group1:checkpoint:1") + actual := getCheckpointID(uint16(1), "group1") + if !bytes.Equal(actual, expected) { + t.Errorf("Unexpected result. Expected: %s, Got: %s", expected, actual) + } +} + +func TestGetCheckpointIDWithInvalidGroupName(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Errorf("Expected panic but did not occur") + } + }() + + getCheckpointID(uint16(1), "group.with.dot") +}