| Index: go/src/infra/gae/libs/wrapper/memory/key_test.go
|
| diff --git a/go/src/infra/gae/libs/wrapper/memory/key_test.go b/go/src/infra/gae/libs/wrapper/memory/key_test.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..511bec90df2737fb66687c727eb28e2799583263
|
| --- /dev/null
|
| +++ b/go/src/infra/gae/libs/wrapper/memory/key_test.go
|
| @@ -0,0 +1,50 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package memory
|
| +
|
| +import (
|
| + "bytes"
|
| + "fmt"
|
| + "golang.org/x/net/context"
|
| + "testing"
|
| +
|
| + "appengine/datastore"
|
| +
|
| + "infra/gae/libs/wrapper"
|
| +
|
| + . "github.com/smartystreets/goconvey/convey"
|
| +)
|
| +
|
| +func shouldEqualKey(ai interface{}, bis ...interface{}) string {
|
| + if len(bis) != 1 {
|
| + return "too many bees!"
|
| + }
|
| + a, b := ai.(*datastore.Key), bis[0].(*datastore.Key)
|
| + if !a.Equal(b) {
|
| + return fmt.Sprintf("Expected: %s\nActual: %s", b.String(), a.String())
|
| + }
|
| + return ""
|
| +}
|
| +
|
| +func TestKeyBinaryStuff(t *testing.T) {
|
| + Convey("Key binary encoding", t, func() {
|
| + c := Use(Enable(context.Background()))
|
| + c, err := wrapper.GetGI(c).Namespace("bobspace")
|
| + So(err, ShouldBeNil)
|
| + ds := wrapper.GetDS(c)
|
| +
|
| + k := ds.NewKey("Bunny", "", 10, ds.NewKey("Parent", "Cat", 0, nil))
|
| + So(k.Namespace(), ShouldEqual, "bobspace")
|
| +
|
| + b := &bytes.Buffer{}
|
| + writeKey(b, withNS, k)
|
| +
|
| + newk, err := readKey(b, withNS)
|
| + So(err, ShouldBeNil)
|
| + So(k.Namespace(), ShouldEqual, "bobspace")
|
| + So(newk, shouldEqualKey, k)
|
| + So(b.Bytes(), ShouldBeEmpty)
|
| + })
|
| +}
|
|
|