Skip to content

Commit

Permalink
fix(datastore): Correcting string representation of Key (#8363)
Browse files Browse the repository at this point in the history
* fix(datastore): Correcting string representation of Key

* fix(datastore): Adding description to GetMulti tests
  • Loading branch information
bhshkh committed Aug 8, 2023
1 parent 2952e20 commit 4cb1211
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
28 changes: 18 additions & 10 deletions datastore/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,27 @@ func TestIntegration_GetMulti(t *testing.T) {
p := NameKey("X", "x"+suffix, nil)

cases := []struct {
key *Key
put bool
desc string
key *Key
put bool
x *X
}{
{key: NameKey("X", "item1", p), put: true},
{key: NameKey("X", "item2", p), put: false},
{key: NameKey("X", "item3", p), put: false},
{key: NameKey("X", "item3", p), put: false},
{key: NameKey("X", "item4", p), put: true},
{desc: "Successful get", key: NameKey("X", "item1", p), put: true, x: &X{I: 1}},
{desc: "No such entity error", key: NameKey("X", "item2", p), put: false},
{desc: "No such entity error", key: NameKey("X", "item3", p), put: false},
{desc: "Duplicate keys in GetMulti with no such entity error", key: NameKey("X", "item3", p), put: false},
{desc: "First key in the pair of keys with same Kind and Name but different Namespace", key: &Key{Kind: "X", Name: "item5", Namespace: "nm1"}, put: true, x: &X{I: 5}},
{desc: "Second key in the pair of keys with same Kind and Name but different Namespace", key: &Key{Kind: "X", Name: "item5", Namespace: "nm2"}, put: true, x: &X{I: 6}},
}

var src, dst []*X
var src, dst, wantDst []*X
var srcKeys, dstKeys []*Key
for _, c := range cases {
dst = append(dst, &X{})
dstKeys = append(dstKeys, c.key)
wantDst = append(wantDst, c.x)
if c.put {
src = append(src, &X{})
src = append(src, c.x)
srcKeys = append(srcKeys, c.key)
}
}
Expand All @@ -389,7 +393,11 @@ func TestIntegration_GetMulti(t *testing.T) {
got, want = err, ErrNoSuchEntity
}
if got != want {
t.Errorf("MultiError[%d] == %v, want %v", i, got, want)
t.Errorf("%s: MultiError[%d] == %v, want %v", cases[i].desc, i, got, want)
}

if got == nil && *dst[i] != *wantDst[i] {
t.Errorf("%s: client.GetMulti got %+v, want %+v", cases[i].desc, dst[i], wantDst[i])
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions datastore/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (k *Key) marshal(b *bytes.Buffer) {
} else {
b.WriteString(strconv.FormatInt(k.ID, 10))
}
if k.Namespace != "" {
b.WriteByte(',')
b.WriteString(k.Namespace)
}
}

// String returns a string representation of the key.
Expand Down

0 comments on commit 4cb1211

Please sign in to comment.