Skip to content

Commit

Permalink
feat: validate dot in group name (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzyildirim authored Nov 10, 2023
1 parent fa3cb73 commit c8a6032
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion couchbase/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package couchbase
import (
"context"
"errors"
"github.com/couchbase/gocbcore/v10"

Check failure on line 6 in couchbase/metadata.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed (gofumpt)
"strconv"
"strings"
"sync"

Check failure on line 9 in couchbase/metadata.go

View workflow job for this annotation

GitHub Actions / build

File is not `gofumpt`-ed (gofumpt)

"github.com/Trendyol/go-dcp/wrapper"
Expand All @@ -19,7 +21,6 @@ import (

"github.com/json-iterator/go"

"github.com/couchbase/gocbcore/v10"
"github.com/couchbase/gocbcore/v10/memd"
)

Expand Down Expand Up @@ -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)))
}
24 changes: 24 additions & 0 deletions couchbase/metedata_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit c8a6032

Please sign in to comment.