OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package memory |
| 6 |
| 7 import ( |
| 8 "bytes" |
| 9 "fmt" |
| 10 "infra/gae/libs/wrapper" |
| 11 "testing" |
| 12 |
| 13 . "github.com/smartystreets/goconvey/convey" |
| 14 "golang.org/x/net/context" |
| 15 |
| 16 "appengine/datastore" |
| 17 ) |
| 18 |
| 19 func shouldEqualKey(ai interface{}, bis ...interface{}) string { |
| 20 if len(bis) != 1 { |
| 21 return "too many bees!" |
| 22 } |
| 23 a, b := ai.(*datastore.Key), bis[0].(*datastore.Key) |
| 24 if !a.Equal(b) { |
| 25 return fmt.Sprintf("Expected: %s\nActual: %s", b.String(), a.S
tring()) |
| 26 } |
| 27 return "" |
| 28 } |
| 29 |
| 30 func TestKeyBinaryStuff(t *testing.T) { |
| 31 t.Parallel() |
| 32 |
| 33 Convey("Key binary encoding", t, func() { |
| 34 c := Use(Enable(context.Background())) |
| 35 c, err := wrapper.GetGI(c).Namespace("bobspace") |
| 36 So(err, ShouldBeNil) |
| 37 ds := wrapper.GetDS(c) |
| 38 |
| 39 k := ds.NewKey("Bunny", "", 10, ds.NewKey("Parent", "Cat", 0, ni
l)) |
| 40 So(k.Namespace(), ShouldEqual, "bobspace") |
| 41 |
| 42 b := &bytes.Buffer{} |
| 43 writeKey(b, withNS, k) |
| 44 |
| 45 newk, err := readKey(b, withNS) |
| 46 So(err, ShouldBeNil) |
| 47 So(k.Namespace(), ShouldEqual, "bobspace") |
| 48 So(newk, shouldEqualKey, k) |
| 49 So(b.Bytes(), ShouldBeEmpty) |
| 50 }) |
| 51 } |
OLD | NEW |