| Index: service/rawdatastore/datastore_key_test.go
|
| diff --git a/helper/datastore_key_test.go b/service/rawdatastore/datastore_key_test.go
|
| similarity index 57%
|
| rename from helper/datastore_key_test.go
|
| rename to service/rawdatastore/datastore_key_test.go
|
| index b8160afaab5386da9001ed28a629f8101f5239e1..8bb1fc16f7bff704ffebbe3c9c7fae10d208cf42 100644
|
| --- a/helper/datastore_key_test.go
|
| +++ b/service/rawdatastore/datastore_key_test.go
|
| @@ -2,22 +2,21 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -package helper
|
| +package rawdatastore
|
|
|
| import (
|
| "encoding/json"
|
| "fmt"
|
| "testing"
|
|
|
| - "github.com/luci/gae"
|
| . "github.com/smartystreets/goconvey/convey"
|
| )
|
|
|
| -func mkKey(aid, ns string, elems ...interface{}) gae.DSKey {
|
| +func mkKey(aid, ns string, elems ...interface{}) Key {
|
| if len(elems)%2 != 0 {
|
| panic("odd number of tokens")
|
| }
|
| - toks := make([]gae.DSKeyTok, len(elems)/2)
|
| + toks := make([]KeyTok, len(elems)/2)
|
| for i := 0; i < len(elems); i += 2 {
|
| toks[i/2].Kind = elems[i].(string)
|
| switch x := elems[i+1].(type) {
|
| @@ -29,14 +28,14 @@ func mkKey(aid, ns string, elems ...interface{}) gae.DSKey {
|
| panic("bad token id")
|
| }
|
| }
|
| - return NewDSKeyToks(aid, ns, toks)
|
| + return NewKeyToks(aid, ns, toks)
|
| }
|
|
|
| func ShouldEqualKey(actual interface{}, expected ...interface{}) string {
|
| if len(expected) != 1 {
|
| return fmt.Sprintf("Assertion requires 1 expected value, got %d", len(expected))
|
| }
|
| - if DSKeysEqual(actual.(gae.DSKey), expected[0].(gae.DSKey)) {
|
| + if KeysEqual(actual.(Key), expected[0].(Key)) {
|
| return ""
|
| }
|
| return fmt.Sprintf("Expected: %q\nActual: %q", actual, expected[0])
|
| @@ -45,90 +44,90 @@ func ShouldEqualKey(actual interface{}, expected ...interface{}) string {
|
| func TestKeyEncode(t *testing.T) {
|
| t.Parallel()
|
|
|
| - keys := []gae.DSKey{
|
| + keys := []Key{
|
| mkKey("appid", "ns", "kind", 1),
|
| mkKey("appid", "ns", "nerd", "moo"),
|
| mkKey("appid", "ns", "parent", 10, "renerd", "moo"),
|
| }
|
|
|
| - Convey("DSKey Round trip", t, func() {
|
| + Convey("Key Round trip", t, func() {
|
| for _, k := range keys {
|
| k := k
|
| Convey(k.String(), func() {
|
| - enc := DSKeyEncode(k)
|
| - aid, ns, toks, err := DSKeyToksDecode(enc)
|
| + enc := KeyEncode(k)
|
| + aid, ns, toks, err := KeyToksDecode(enc)
|
| So(err, ShouldBeNil)
|
| - dec := NewDSKeyToks(aid, ns, toks)
|
| + dec := NewKeyToks(aid, ns, toks)
|
| So(dec, ShouldNotBeNil)
|
| So(dec, ShouldEqualKey, k)
|
|
|
| - dec2, err := NewDSKeyFromEncoded(enc)
|
| + dec2, err := NewKeyFromEncoded(enc)
|
| So(err, ShouldBeNil)
|
| So(dec2, ShouldEqualKey, dec)
|
| So(dec2, ShouldEqualKey, k)
|
| })
|
|
|
| Convey(k.String()+" (json)", func() {
|
| - data, err := DSKeyMarshalJSON(k)
|
| + data, err := KeyMarshalJSON(k)
|
| So(err, ShouldBeNil)
|
|
|
| - aid, ns, toks, err := DSKeyUnmarshalJSON(data)
|
| + aid, ns, toks, err := KeyUnmarshalJSON(data)
|
| So(err, ShouldBeNil)
|
| - So(NewDSKeyToks(aid, ns, toks), ShouldEqualKey, k)
|
| + So(NewKeyToks(aid, ns, toks), ShouldEqualKey, k)
|
| })
|
| }
|
| })
|
|
|
| - Convey("NewDSKey", t, func() {
|
| + Convey("NewKey", t, func() {
|
| Convey("single", func() {
|
| - k := NewDSKey("appid", "ns", "kind", "", 1, nil)
|
| + k := NewKey("appid", "ns", "kind", "", 1, nil)
|
| So(k, ShouldEqualKey, keys[0])
|
| })
|
|
|
| Convey("nest", func() {
|
| - k := NewDSKey("appid", "ns", "renerd", "moo", 0,
|
| - NewDSKey("appid", "ns", "parent", "", 10, nil))
|
| + k := NewKey("appid", "ns", "renerd", "moo", 0,
|
| + NewKey("appid", "ns", "parent", "", 10, nil))
|
| So(k, ShouldEqualKey, keys[2])
|
| })
|
| })
|
|
|
| - Convey("DSKey bad encoding", t, func() {
|
| + Convey("Key bad encoding", t, func() {
|
| Convey("extra junk before", func() {
|
| - enc := DSKeyEncode(keys[2])
|
| - _, _, _, err := DSKeyToksDecode("/" + enc)
|
| + enc := KeyEncode(keys[2])
|
| + _, _, _, err := KeyToksDecode("/" + enc)
|
| So(err, ShouldErrLike, "illegal base64")
|
| })
|
|
|
| Convey("extra junk after", func() {
|
| - enc := DSKeyEncode(keys[2])
|
| - _, _, _, err := DSKeyToksDecode(enc[:len(enc)-1])
|
| + enc := KeyEncode(keys[2])
|
| + _, _, _, err := KeyToksDecode(enc[:len(enc)-1])
|
| So(err, ShouldErrLike, "EOF")
|
| })
|
|
|
| Convey("json encoding includes quotes", func() {
|
| - data, err := DSKeyMarshalJSON(keys[0])
|
| + data, err := KeyMarshalJSON(keys[0])
|
| So(err, ShouldBeNil)
|
|
|
| - _, _, _, err = DSKeyUnmarshalJSON(append(data, '!'))
|
| + _, _, _, err = KeyUnmarshalJSON(append(data, '!'))
|
| So(err, ShouldErrLike, "bad JSON key")
|
| })
|
| })
|
| }
|
|
|
| -type dumbKey1 struct{ gae.DSKey }
|
| +type dumbKey1 struct{ Key }
|
|
|
| func (dk dumbKey1) Namespace() string { return "ns" }
|
| -func (dk dumbKey1) Parent() gae.DSKey { return dk.DSKey }
|
| +func (dk dumbKey1) Parent() Key { return dk.Key }
|
| func (dk dumbKey1) String() string { return "dumbKey1" }
|
|
|
| -type dumbKey2 struct{ gae.DSKey }
|
| +type dumbKey2 struct{ Key }
|
|
|
| /// This is the dumb part... can't have both IDs set.
|
| func (dk dumbKey2) IntID() int64 { return 1 }
|
| func (dk dumbKey2) StringID() string { return "wat" }
|
|
|
| func (dk dumbKey2) Kind() string { return "kind" }
|
| -func (dk dumbKey2) Parent() gae.DSKey { return nil }
|
| +func (dk dumbKey2) Parent() Key { return nil }
|
| func (dk dumbKey2) Namespace() string { return "ns" }
|
| func (dk dumbKey2) AppID() string { return "aid" }
|
| func (dk dumbKey2) String() string { return "dumbKey2" }
|
| @@ -138,15 +137,15 @@ func TestBadKeyEncode(t *testing.T) {
|
|
|
| Convey("bad keys", t, func() {
|
| Convey("incomplete", func() {
|
| - So(DSKeyIncomplete(mkKey("aid", "ns", "kind", 1)), ShouldBeFalse)
|
| - So(DSKeyIncomplete(mkKey("aid", "ns", "kind", 0)), ShouldBeTrue)
|
| + So(KeyIncomplete(mkKey("aid", "ns", "kind", 1)), ShouldBeFalse)
|
| + So(KeyIncomplete(mkKey("aid", "ns", "kind", 0)), ShouldBeTrue)
|
| })
|
|
|
| Convey("invalid", func() {
|
| - So(DSKeyValid(mkKey("aid", "ns", "hat", "face", "__kind__", 1), "ns", true), ShouldBeTrue)
|
| - So(DSKeyValid(mkKey("aid", "ns", "hat", "face", "kind", 1), "wat", false), ShouldBeFalse)
|
| + So(KeyValid(mkKey("aid", "ns", "hat", "face", "__kind__", 1), "ns", true), ShouldBeTrue)
|
| + So(KeyValid(mkKey("aid", "ns", "hat", "face", "kind", 1), "wat", false), ShouldBeFalse)
|
|
|
| - bads := []gae.DSKey{
|
| + bads := []Key{
|
| nil,
|
| mkKey("", "ns", "hat", "face"),
|
| mkKey("aid", "ns", "base", 1, "", "id"),
|
| @@ -161,18 +160,18 @@ func TestBadKeyEncode(t *testing.T) {
|
| s = k.String()
|
| }
|
| Convey(s, func() {
|
| - So(DSKeyValid(k, "ns", false), ShouldBeFalse)
|
| + So(KeyValid(k, "ns", false), ShouldBeFalse)
|
| })
|
| }
|
| })
|
| })
|
| }
|
|
|
| -type keyWrap struct{ gae.DSKey }
|
| +type keyWrap struct{ Key }
|
|
|
| -func (k keyWrap) Parent() gae.DSKey {
|
| - if k.DSKey.Parent() != nil {
|
| - return keyWrap{k.DSKey.Parent()}
|
| +func (k keyWrap) Parent() Key {
|
| + if k.Key.Parent() != nil {
|
| + return keyWrap{k.Key.Parent()}
|
| }
|
| return nil
|
| }
|
| @@ -180,60 +179,60 @@ func (k keyWrap) Parent() gae.DSKey {
|
| func TestMiscKey(t *testing.T) {
|
| t.Parallel()
|
|
|
| - Convey("DSKeyRoot", t, func() {
|
| + Convey("KeyRoot", t, func() {
|
| k := mkKey("appid", "ns", "parent", 10, "renerd", "moo")
|
| r := mkKey("appid", "ns", "parent", 10)
|
| - So(DSKeyRoot(k), ShouldEqualKey, r)
|
| - So(DSKeyRoot(nil), ShouldBeNil)
|
| + So(KeyRoot(k), ShouldEqualKey, r)
|
| + So(KeyRoot(nil), ShouldBeNil)
|
| })
|
|
|
| - Convey("DSKeySplit", t, func() {
|
| - // keyWrap forces DSKeySplit to not take the GenericDSKey shortcut.
|
| + Convey("KeySplit", t, func() {
|
| + // keyWrap forces KeySplit to not take the GenericKey shortcut.
|
| k := keyWrap{mkKey("appid", "ns", "parent", 10, "renerd", "moo")}
|
| - aid, ns, toks := DSKeySplit(k)
|
| + aid, ns, toks := KeySplit(k)
|
| So(aid, ShouldEqual, "appid")
|
| So(ns, ShouldEqual, "ns")
|
| - So(toks, ShouldResemble, []gae.DSKeyTok{
|
| + So(toks, ShouldResemble, []KeyTok{
|
| {Kind: "parent", IntID: 10},
|
| {Kind: "renerd", StringID: "moo"},
|
| })
|
| })
|
|
|
| - Convey("DSKeySplit (nil)", t, func() {
|
| - aid, ns, toks := DSKeySplit(nil)
|
| + Convey("KeySplit (nil)", t, func() {
|
| + aid, ns, toks := KeySplit(nil)
|
| So(aid, ShouldEqual, "")
|
| So(ns, ShouldEqual, "")
|
| - So(toks, ShouldResemble, []gae.DSKeyTok(nil))
|
| + So(toks, ShouldResemble, []KeyTok(nil))
|
| })
|
|
|
| - Convey("DSKeySplit ((*GenericDSKey)(nil))", t, func() {
|
| - aid, ns, toks := DSKeySplit((*GenericDSKey)(nil))
|
| + Convey("KeySplit ((*GenericKey)(nil))", t, func() {
|
| + aid, ns, toks := KeySplit((*GenericKey)(nil))
|
| So(aid, ShouldEqual, "")
|
| So(ns, ShouldEqual, "")
|
| - So(toks, ShouldResemble, []gae.DSKeyTok(nil))
|
| + So(toks, ShouldResemble, []KeyTok(nil))
|
| })
|
|
|
| - Convey("DSKeysEqual", t, func() {
|
| + Convey("KeysEqual", t, func() {
|
| k1 := mkKey("a", "n", "knd", 1)
|
| k2 := mkKey("a", "n", "knd", 1)
|
| - So(DSKeysEqual(k1, k2), ShouldBeTrue)
|
| + So(KeysEqual(k1, k2), ShouldBeTrue)
|
| k3 := mkKey("a", "n", "knd", 2)
|
| - So(DSKeysEqual(k1, k3), ShouldBeFalse)
|
| + So(KeysEqual(k1, k3), ShouldBeFalse)
|
| })
|
|
|
| - Convey("DSKeyString", t, func() {
|
| + Convey("KeyString", t, func() {
|
| k1 := mkKey("a", "n", "knd", 1, "other", "wat")
|
| - So(DSKeyString(k1), ShouldEqual, "/knd,1/other,wat")
|
| - So(DSKeyString(nil), ShouldEqual, "")
|
| + So(KeyString(k1), ShouldEqual, "/knd,1/other,wat")
|
| + So(KeyString(nil), ShouldEqual, "")
|
| })
|
|
|
| - Convey("*GenericDSKey supports json encoding", t, func() {
|
| + Convey("*GenericKey supports json encoding", t, func() {
|
| type TestStruct struct {
|
| - Key *GenericDSKey
|
| + Key *GenericKey
|
| }
|
| t := &TestStruct{
|
| - NewDSKey("aid", "ns", "kind", "id", 0,
|
| - NewDSKey("aid", "ns", "parent", "", 1, nil),
|
| + NewKey("aid", "ns", "kind", "id", 0,
|
| + NewKey("aid", "ns", "parent", "", 1, nil),
|
| )}
|
| d, err := json.Marshal(t)
|
| So(err, ShouldBeNil)
|
|
|