Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: validate dot in group name #72

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion couchbase/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
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 @@

"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 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")
}
Loading