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 "golang.org/x/net/context" |
| 11 "testing" |
| 12 |
| 13 "appengine/datastore" |
| 14 |
| 15 "infra/gae/libs/wrapper" |
| 16 |
| 17 . "github.com/smartystreets/goconvey/convey" |
| 18 ) |
| 19 |
| 20 func shouldEqualKey(ai interface{}, bis ...interface{}) string { |
| 21 if len(bis) != 1 { |
| 22 return "too many bees!" |
| 23 } |
| 24 a, b := ai.(*datastore.Key), bis[0].(*datastore.Key) |
| 25 if !a.Equal(b) { |
| 26 return fmt.Sprintf("Expected: %s\nActual: %s", b.String(), a.S
tring()) |
| 27 } |
| 28 return "" |
| 29 } |
| 30 |
| 31 func TestKeyBinaryStuff(t *testing.T) { |
| 32 Convey("Key binary encoding", t, func() { |
| 33 c := Use(Enable(context.Background())) |
| 34 c, err := wrapper.GetGI(c).Namespace("bobspace") |
| 35 So(err, ShouldBeNil) |
| 36 ds := wrapper.GetDS(c) |
| 37 |
| 38 k := ds.NewKey("Bunny", "", 10, ds.NewKey("Parent", "Cat", 0, ni
l)) |
| 39 So(k.Namespace(), ShouldEqual, "bobspace") |
| 40 |
| 41 b := &bytes.Buffer{} |
| 42 writeKey(b, withNS, k) |
| 43 |
| 44 newk, err := readKey(b, withNS) |
| 45 So(err, ShouldBeNil) |
| 46 So(k.Namespace(), ShouldEqual, "bobspace") |
| 47 So(newk, shouldEqualKey, k) |
| 48 So(b.Bytes(), ShouldBeEmpty) |
| 49 }) |
| 50 } |
OLD | NEW |