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

Side by Side Diff: go/src/infra/gae/libs/wrapper/dummy_test.go

Issue 1240573002: Reland: Refactor current GAE abstraction library to be free of the SDK* (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: expand coverage range to fit 32bit test expectations Created 5 years, 5 months 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
(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 wrapper
6
7 import (
8 "math/rand"
9 "testing"
10 "time"
11
12 "golang.org/x/net/context"
13
14 "appengine/memcache"
15
16 . "github.com/smartystreets/goconvey/convey"
17 "infra/libs/clock/testclock"
18 )
19
20 func TestContextAccess(t *testing.T) {
21 Convey("Context Access", t, func() {
22 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
23 c, _ := testclock.UseTime(context.Background(), now)
24
25 Convey("blank", func() {
26 So(GetDS(c), ShouldBeNil)
27 So(GetMC(c), ShouldBeNil)
28 So(GetTQ(c), ShouldBeNil)
29 So(GetGI(c), ShouldBeNil)
30 })
31
32 Convey("DS", func() {
33 c = SetDS(c, DummyDS())
34 So(GetDS(c), ShouldNotBeNil)
35 So(func() { GetDS(c).Kind(nil) }, ShouldPanic)
36 })
37
38 Convey("MC", func() {
39 c = SetMC(c, DummyMC())
40 So(GetMC(c), ShouldNotBeNil)
41 So(func() { GetMC(c).InflateCodec(memcache.Codec{}) }, S houldPanic)
42 })
43
44 Convey("TQ", func() {
45 c = SetTQ(c, DummyTQ())
46 So(GetTQ(c), ShouldNotBeNil)
47 So(func() { GetTQ(c).Purge("") }, ShouldPanic)
48 })
49
50 Convey("GI", func() {
51 c = SetGI(c, DummyGI())
52 So(GetGI(c), ShouldNotBeNil)
53 So(func() { GetGI(c).Datacenter() }, ShouldPanic)
54 })
55
56 Convey("QY", func() {
57 q := DummyQY()
58 So(func() { q.Distinct() }, ShouldPanic)
59 })
60
61 Convey("MathRand", func() {
62 r := rand.New(rand.NewSource(now.UnixNano()))
63 i := r.Int()
64
65 // when it's unset it picks the current time every time
66 So(GetMathRand(c).Int(), ShouldEqual, i)
67 So(GetMathRand(c).Int(), ShouldEqual, i)
68
69 // But we could set it to something concrete to have it persist.
70 c = SetMathRand(c, rand.New(rand.NewSource(now.UnixNano( ))))
71 r = rand.New(rand.NewSource(now.UnixNano()))
72 So(GetMathRand(c).Int(), ShouldEqual, r.Int())
73 So(GetMathRand(c).Int(), ShouldEqual, r.Int())
74 })
75 })
76 }
OLDNEW
« no previous file with comments | « go/src/infra/gae/libs/wrapper/dummy.go ('k') | go/src/infra/gae/libs/wrapper/gae/commonErrors/commonErrors.infra_testing » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698