Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: service/datastore/raw_interface_test.go

Issue 1516173002: Fix error message from KeyForObj when passing an invalid struct. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Fix GetMetaDefault silliness Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package datastore 5 package datastore
6 6
7 import ( 7 import (
8 "testing" 8 "testing"
9 9
10 . "github.com/smartystreets/goconvey/convey" 10 . "github.com/smartystreets/goconvey/convey"
11 ) 11 )
12 12
13 func TestMultiMetaGetter(t *testing.T) { 13 func TestMultiMetaGetter(t *testing.T) {
14 t.Parallel() 14 t.Parallel()
15 15
16 Convey("Test MultiMetaGetter", t, func() { 16 Convey("Test MultiMetaGetter", t, func() {
17 Convey("nil", func() { 17 Convey("nil", func() {
18 mmg := NewMultiMetaGetter(nil) 18 mmg := NewMultiMetaGetter(nil)
19 val, err := mmg.GetMeta(7, "hi") 19 val, err := mmg.GetMeta(7, "hi")
20 So(err, ShouldEqual, ErrMetaFieldUnset) 20 So(err, ShouldEqual, ErrMetaFieldUnset)
21 So(val, ShouldBeNil) 21 So(val, ShouldBeNil)
22 22
23 » » » So(mmg.GetMetaDefault(7, "hi", "value"), ShouldEqual, "v alue") 23 » » » v, err := GetMetaDefault(mmg.GetSingle(7), "hi", "value" )
24 » » » So(err, ShouldBeNil)
25 » » » So(v, ShouldEqual, "value")
24 26
25 m := mmg.GetSingle(10) 27 m := mmg.GetSingle(10)
26 val, err = m.GetMeta("hi") 28 val, err = m.GetMeta("hi")
27 So(err, ShouldEqual, ErrMetaFieldUnset) 29 So(err, ShouldEqual, ErrMetaFieldUnset)
28 So(val, ShouldBeNil) 30 So(val, ShouldBeNil)
29 » » » So(m.GetMetaDefault("hi", "value"), ShouldEqual, "value" ) 31
32 » » » v, err = GetMetaDefault(m, "hi", "value")
33 » » » So(err, ShouldBeNil)
34 » » » So(v, ShouldEqual, "value")
30 }) 35 })
31 36
32 Convey("stuff", func() { 37 Convey("stuff", func() {
33 pmaps := []PropertyMap{{}, nil, {}} 38 pmaps := []PropertyMap{{}, nil, {}}
34 So(pmaps[0].SetMeta("hi", "thing"), ShouldBeNil) 39 So(pmaps[0].SetMeta("hi", "thing"), ShouldBeNil)
35 So(pmaps[2].SetMeta("key", 100), ShouldBeNil) 40 So(pmaps[2].SetMeta("key", 100), ShouldBeNil)
36 mmg := NewMultiMetaGetter(pmaps) 41 mmg := NewMultiMetaGetter(pmaps)
37 42
38 // oob is OK 43 // oob is OK
39 » » » So(mmg.GetMetaDefault(7, "hi", "value"), ShouldEqual, "v alue") 44 » » » v, err := GetMetaDefault(mmg.GetSingle(7), "hi", "value" )
45 » » » So(err, ShouldBeNil)
46 » » » So(v, ShouldEqual, "value")
40 47
41 // nil is OK 48 // nil is OK
42 » » » So(mmg.GetMetaDefault(1, "key", true), ShouldEqual, true ) 49 » » » v, err = GetMetaDefault(mmg.GetSingle(1), "key", true)
50 » » » So(err, ShouldBeNil)
51 » » » So(v, ShouldEqual, true)
43 52
44 val, err := mmg.GetMeta(0, "hi") 53 val, err := mmg.GetMeta(0, "hi")
45 So(err, ShouldBeNil) 54 So(err, ShouldBeNil)
46 So(val, ShouldEqual, "thing") 55 So(val, ShouldEqual, "thing")
47 56
48 » » » So(mmg.GetMetaDefault(2, "key", 20), ShouldEqual, 100) 57 » » » v, err = GetMetaDefault(mmg.GetSingle(2), "key", 20)
58 » » » So(err, ShouldBeNil)
59 » » » So(v, ShouldEqual, 100)
49 }) 60 })
50 }) 61 })
51 } 62 }
OLDNEW
« service/datastore/pls_test.go ('K') | « service/datastore/raw_interface.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698