From cc0f0a4d82bea0e6818c8bf5a3beb96369fd7bce Mon Sep 17 00:00:00 2001 From: Stefan Liu Date: Mon, 28 Sep 2020 21:04:28 +0800 Subject: [PATCH] GOCBC-996: Remove `[]` from id for `CollectionMap.At` and `Exist` 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 `[]` which looks like a copy and paste bug from the list/set data structures. Changes ------- Don't wrap the id in `[]` 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 Tested-by: Charles Dixon --- collection_ds.go | 4 ++-- collection_ds_test.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/collection_ds.go b/collection_ds.go index c22796f7..9f2281bf 100644 --- a/collection_ds.go +++ b/collection_ds.go @@ -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 @@ -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 diff --git a/collection_ds_test.go b/collection_ds_test.go index 09e0a4a3..a1335293 100644 --- a/collection_ds_test.go +++ b/collection_ds_test.go @@ -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) @@ -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)