OLD | NEW |
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 // +build appengine | 5 // +build appengine |
6 | 6 |
7 package prod | 7 package prod |
8 | 8 |
9 import ( | 9 import ( |
10 "testing" | 10 "testing" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 Convey("Can probe/change Namespace", func() { | 56 Convey("Can probe/change Namespace", func() { |
57 So(inf.GetNamespace(), ShouldEqual, "") | 57 So(inf.GetNamespace(), ShouldEqual, "") |
58 ctx, err = inf.Namespace("wat") | 58 ctx, err = inf.Namespace("wat") |
59 So(err, ShouldBeNil) | 59 So(err, ShouldBeNil) |
60 inf = info.Get(ctx) | 60 inf = info.Get(ctx) |
61 So(inf.GetNamespace(), ShouldEqual, "wat") | 61 So(inf.GetNamespace(), ShouldEqual, "wat") |
62 ds = datastore.Get(ctx) | 62 ds = datastore.Get(ctx) |
63 So(ds.MakeKey("Hello", "world").Namespace(), ShouldEqual
, "wat") | 63 So(ds.MakeKey("Hello", "world").Namespace(), ShouldEqual
, "wat") |
64 }) | 64 }) |
65 | 65 |
| 66 Convey("Can get non-transactional context", func() { |
| 67 ctx, err := inf.Namespace("foo") |
| 68 So(err, ShouldBeNil) |
| 69 ds = datastore.Get(ctx) |
| 70 inf = info.Get(ctx) |
| 71 |
| 72 ds.RunInTransaction(func(ctx context.Context) error { |
| 73 So(ds.MakeKey("Foo", "bar").Namespace(), ShouldE
qual, "foo") |
| 74 |
| 75 So(ds.Put(&TestStruct{ValueI: []int64{100}}), Sh
ouldBeNil) |
| 76 |
| 77 err = datastore.GetNoTxn(ctx).RunInTransaction(f
unc(ctx context.Context) error { |
| 78 ds = datastore.Get(ctx) |
| 79 So(ds.MakeKey("Foo", "bar").Namespace(),
ShouldEqual, "foo") |
| 80 So(ds.Put(&TestStruct{ValueI: []int64{10
0}}), ShouldBeNil) |
| 81 return nil |
| 82 }, nil) |
| 83 So(err, ShouldBeNil) |
| 84 |
| 85 return nil |
| 86 }, nil) |
| 87 }) |
| 88 |
66 Convey("Can Put/Get", func() { | 89 Convey("Can Put/Get", func() { |
67 orig := TestStruct{ | 90 orig := TestStruct{ |
68 ValueI: []int64{1, 7, 946688461000000, 996688461
000000}, | 91 ValueI: []int64{1, 7, 946688461000000, 996688461
000000}, |
69 ValueB: []bool{true, false}, | 92 ValueB: []bool{true, false}, |
70 ValueS: []string{"hello", "world"}, | 93 ValueS: []string{"hello", "world"}, |
71 ValueF: []float64{1.0, 7.0, 946688461000000.0, 9
96688461000000.0}, | 94 ValueF: []float64{1.0, 7.0, 946688461000000.0, 9
96688461000000.0}, |
72 ValueBS: [][]byte{ | 95 ValueBS: [][]byte{ |
73 []byte("allo"), | 96 []byte("allo"), |
74 []byte("hello"), | 97 []byte("hello"), |
75 []byte("world"), | 98 []byte("world"), |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 So(tval, ShouldResemble, pm["Time"][0].Value()) | 205 So(tval, ShouldResemble, pm["Time"][0].Value()) |
183 | 206 |
184 ent := datastore.PropertyMap{ | 207 ent := datastore.PropertyMap{ |
185 "$key": {mpNI(ds.MakeKey("Something", "value"))}
, | 208 "$key": {mpNI(ds.MakeKey("Something", "value"))}
, |
186 } | 209 } |
187 So(ds.Get(&ent), ShouldBeNil) | 210 So(ds.Get(&ent), ShouldBeNil) |
188 So(ent["Time"], ShouldResemble, pm["Time"]) | 211 So(ent["Time"], ShouldResemble, pm["Time"]) |
189 }) | 212 }) |
190 }) | 213 }) |
191 } | 214 } |
OLD | NEW |