diff --git a/couchbase/metadata.go b/couchbase/metadata.go index 1eeff37..460f26b 100644 --- a/couchbase/metadata.go +++ b/couchbase/metadata.go @@ -3,7 +3,9 @@ package couchbase import ( "context" "errors" + "net/url" "strconv" + "strings" "sync" "github.com/Trendyol/go-dcp/wrapper" @@ -147,5 +149,6 @@ func NewCBMetadata(client Client, config *config.Dcp) metadata.Metadata { func getCheckpointID(vbID uint16, groupName string) []byte { // _connector:cbgo:groupName:stdout-listener:checkpoint:vbId - return []byte(helpers.Prefix + groupName + ":checkpoint:" + strconv.Itoa(int(vbID))) + encodedGroupName := strings.ReplaceAll(url.QueryEscape(groupName), ".", "%2E") + return []byte(helpers.Prefix + encodedGroupName + ":checkpoint:" + strconv.Itoa(int(vbID))) } diff --git a/couchbase/metadata_test.go b/couchbase/metadata_test.go new file mode 100644 index 0000000..f9e431e --- /dev/null +++ b/couchbase/metadata_test.go @@ -0,0 +1,27 @@ +package couchbase + +import ( + "testing" +) + +func TestGetCheckpointID(t *testing.T) { + // Define test cases with input and expected output + testCases := []struct { + vbID uint16 + groupName string + expectedID string + }{ + {0, "group:1", "_connector:cbgo:group%3A1:checkpoint:0"}, + {42, "group.2", "_connector:cbgo:group%2E2:checkpoint:42"}, + } + + for _, tc := range testCases { + t.Run(tc.groupName, func(t *testing.T) { + result := string(getCheckpointID(tc.vbID, tc.groupName)) + + if result != tc.expectedID { + t.Errorf("getCheckpointID(%d, %s) = got %s; want %s", tc.vbID, tc.groupName, result, tc.expectedID) + } + }) + } +}