diff --git a/datastore/integration_test.go b/datastore/integration_test.go index 44f1164e042e..5c873e16c2d5 100644 --- a/datastore/integration_test.go +++ b/datastore/integration_test.go @@ -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) } } @@ -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]) } } } diff --git a/datastore/key.go b/datastore/key.go index 5807eedd30a6..6b6ff34d4bd5 100644 --- a/datastore/key.go +++ b/datastore/key.go @@ -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.