Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion client/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type SearchIterator struct {
client *GrpcClient
}

func (itr SearchIterator) init(ctx context.Context) error {
func (itr *SearchIterator) init(ctx context.Context) error {
if itr.batchSize <= 0 {
return errors.New("batch size cannot less than 1")
}
Expand Down
24 changes: 24 additions & 0 deletions entity/collection_attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,27 @@ func (ca databaseResourceGroupsAttr) Valid() error {

return nil
}

type customAttr struct {
collAttrBase
}

// CustomAttribute returns a collection attribute with custom key and value
func CustomAttribute(key, value string) customAttr {
ca := customAttr{}
ca.key = key
ca.value = value
return ca
}

// Valid implements CollectionAttribute
// Custom attributes are considered valid as long as both key and value are non-empty
func (ca customAttr) Valid() error {
if ca.key == "" {
return errors.New("custom attribute key cannot be empty")
}
if ca.value == "" {
return errors.New("custom attribute value cannot be empty")
}
return nil
}
44 changes: 44 additions & 0 deletions entity/collection_attr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,47 @@ func (s *CollectionPartitionKeyIsolationSuite) TestCollectionAutoCompactionEnabl
func TestCollectionPartitionKeyIsolationAttr(t *testing.T) {
suite.Run(t, new(CollectionPartitionKeyIsolationSuite))
}

type CustomAttributeSuite struct {
suite.Suite
}

func (s *CustomAttributeSuite) TestValid() {
type testCase struct {
key string
value string
expectErr bool
}

cases := []testCase{
{key: "custom.key", value: "value", expectErr: false},
{key: "", value: "value", expectErr: true},
{key: "custom.key", value: "", expectErr: true},
{key: "", value: "", expectErr: true},
}

for _, tc := range cases {
s.Run(fmt.Sprintf("key=%s,value=%s", tc.key, tc.value), func() {
ca := CustomAttribute(tc.key, tc.value)
err := ca.Valid()
if tc.expectErr {
s.Error(err)
} else {
s.NoError(err)
}
})
}
}

func (s *CustomAttributeSuite) TestKeyValue() {
key := "custom.test.key"
value := "test.value"
ca := CustomAttribute(key, value)
gotKey, gotValue := ca.KeyValue()
s.Equal(key, gotKey)
s.Equal(value, gotValue)
}

func TestCustomAttribute(t *testing.T) {
suite.Run(t, new(CustomAttributeSuite))
}