Skip to content

Commit

Permalink
GOCBC-996: Remove [] from id for CollectionMap.At and Exist
Browse files Browse the repository at this point in the history
Motivation
-----------
The Map data structure is using invalid paths for At and Exists.
This is causing these functions to be unuseable. They wrap
the id in `[<id>]` which looks like a copy and paste bug from
the list/set data structures.

Changes
-------
Don't wrap the id in `[<id>]` for At and Exists for the map
data structure.

Change-Id: I5f7dfcb506c260603405e5b6b8e0eabcb703425b
Reviewed-on: http://review.couchbase.org/c/gocb/+/137041
Reviewed-by: Charles Dixon <chvckd@gmail.com>
Tested-by: Charles Dixon <chvckd@gmail.com>
  • Loading branch information
devfans authored and chvck committed Sep 28, 2020
1 parent 3fe96bb commit cc0f0a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions collection_ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (cl *CouchbaseMap) Iterator() (map[string]interface{}, error) {
// At retrieves the item for the given id from the map.
func (cl *CouchbaseMap) At(id string, valuePtr interface{}) error {
ops := make([]LookupInSpec, 1)
ops[0] = GetSpec(fmt.Sprintf("[%s]", id), nil)
ops[0] = GetSpec(id, nil)
result, err := cl.collection.LookupIn(cl.id, ops, nil)
if err != nil {
return err
Expand Down Expand Up @@ -202,7 +202,7 @@ func (cl *CouchbaseMap) Remove(id string) error {
// Exists verifies whether or a id exists in the map.
func (cl *CouchbaseMap) Exists(id string) (bool, error) {
ops := make([]LookupInSpec, 1)
ops[0] = ExistsSpec(fmt.Sprintf("[%s]", id), nil)
ops[0] = ExistsSpec(id, nil)
result, err := cl.collection.LookupIn(cl.id, ops, nil)
if err != nil {
return false, err
Expand Down
9 changes: 9 additions & 0 deletions collection_ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ func (suite *IntegrationTestSuite) TestMapCrud() {
suite.T().Fatalf("Expected cMap size to be 4 but was %d", size)
}

var test3Val string
err = cMap.At("test3", &test3Val)
suite.Assert().Nil(err, err)
suite.Assert().Equal("test3val", test3Val)

suite.Assert().True(cMap.Exists("test3"))

iter, err := cMap.Iterator()
if err != nil {
suite.T().Fatalf("Failed to get iterator for cMap %v", err)
Expand All @@ -362,6 +369,8 @@ func (suite *IntegrationTestSuite) TestMapCrud() {
suite.T().Fatalf("Failed to remove from cMap %v", err)
}

suite.Assert().False(cMap.Exists("test1"))

size, err = cMap.Size()
if err != nil {
suite.T().Fatalf("Failed to get size of cMap %v", err)
Expand Down

0 comments on commit cc0f0a4

Please sign in to comment.