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

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

Issue 1230303003: Revert "Refactor current GAE abstraction library to be free of the SDK*" (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: 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
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 gae 5 package wrapper
6 6
7 import ( 7 import (
8 "math/rand" 8 "math/rand"
9 "testing" 9 "testing"
10 "time" 10 "time"
11 11
12 "golang.org/x/net/context" 12 "golang.org/x/net/context"
13 13
14 » "github.com/luci/luci-go/common/clock/testclock" 14 » "appengine/memcache"
15 15
16 . "github.com/smartystreets/goconvey/convey" 16 . "github.com/smartystreets/goconvey/convey"
17 "infra/libs/clock/testclock"
17 ) 18 )
18 19
19 func TestContextAccess(t *testing.T) { 20 func TestContextAccess(t *testing.T) {
20 Convey("Context Access", t, func() { 21 Convey("Context Access", t, func() {
21 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) 22 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
22 c, _ := testclock.UseTime(context.Background(), now) 23 c, _ := testclock.UseTime(context.Background(), now)
23 24
24 Convey("blank", func() { 25 Convey("blank", func() {
26 So(GetDS(c), ShouldBeNil)
25 So(GetMC(c), ShouldBeNil) 27 So(GetMC(c), ShouldBeNil)
26 So(GetTQ(c), ShouldBeNil) 28 So(GetTQ(c), ShouldBeNil)
27 So(GetGI(c), ShouldBeNil) 29 So(GetGI(c), ShouldBeNil)
28 }) 30 })
29 31
30 » » Convey("RDS", func() { 32 » » Convey("DS", func() {
31 » » » c = SetRDS(c, DummyRDS()) 33 » » » c = SetDS(c, DummyDS())
32 » » » So(GetRDS(c), ShouldNotBeNil) 34 » » » So(GetDS(c), ShouldNotBeNil)
33 » » » So(func() { GetRDS(c).NewKey("", "", 1, nil) }, ShouldPa nic) 35 » » » So(func() { GetDS(c).Kind(nil) }, ShouldPanic)
34 }) 36 })
35 37
36 Convey("MC", func() { 38 Convey("MC", func() {
37 c = SetMC(c, DummyMC()) 39 c = SetMC(c, DummyMC())
38 So(GetMC(c), ShouldNotBeNil) 40 So(GetMC(c), ShouldNotBeNil)
39 » » » So(func() { GetMC(c).Add(nil) }, ShouldPanic) 41 » » » So(func() { GetMC(c).InflateCodec(memcache.Codec{}) }, S houldPanic)
40 }) 42 })
41 43
42 Convey("TQ", func() { 44 Convey("TQ", func() {
43 c = SetTQ(c, DummyTQ()) 45 c = SetTQ(c, DummyTQ())
44 So(GetTQ(c), ShouldNotBeNil) 46 So(GetTQ(c), ShouldNotBeNil)
45 So(func() { GetTQ(c).Purge("") }, ShouldPanic) 47 So(func() { GetTQ(c).Purge("") }, ShouldPanic)
46 }) 48 })
47 49
48 Convey("GI", func() { 50 Convey("GI", func() {
49 c = SetGI(c, DummyGI()) 51 c = SetGI(c, DummyGI())
50 So(GetGI(c), ShouldNotBeNil) 52 So(GetGI(c), ShouldNotBeNil)
51 So(func() { GetGI(c).Datacenter() }, ShouldPanic) 53 So(func() { GetGI(c).Datacenter() }, ShouldPanic)
52 }) 54 })
53 55
54 Convey("QY", func() { 56 Convey("QY", func() {
55 q := DummyQY() 57 q := DummyQY()
56 So(func() { q.Distinct() }, ShouldPanic) 58 So(func() { q.Distinct() }, ShouldPanic)
57 }) 59 })
58 60
59 Convey("MathRand", func() { 61 Convey("MathRand", func() {
60 » » » // Note that the non-randomness below is because time is fixed at the 62 » » » r := rand.New(rand.NewSource(now.UnixNano()))
61 » » » // top of the outer test function. Normally it would evo lve with time. 63 » » » i := r.Int()
62 » » » Convey("unset", func() {
63 » » » » r := rand.New(rand.NewSource(now.UnixNano()))
64 » » » » i := r.Int()
65 » » » » So(GetMathRand(c).Int(), ShouldEqual, i)
66 » » » » So(GetMathRand(c).Int(), ShouldEqual, i)
67 » » » })
68 64
69 » » » Convey("set persistance", func() { 65 » » » // when it's unset it picks the current time every time
70 » » » » c = SetMathRand(c, rand.New(rand.NewSource(now.U nixNano()))) 66 » » » So(GetMathRand(c).Int(), ShouldEqual, i)
71 » » » » r := rand.New(rand.NewSource(now.UnixNano())) 67 » » » So(GetMathRand(c).Int(), ShouldEqual, i)
72 » » » » So(GetMathRand(c).Int(), ShouldEqual, r.Int())
73 » » » » So(GetMathRand(c).Int(), ShouldEqual, r.Int())
74 » » » })
75 68
76 » » » Convey("nil set", func() { 69 » » » // But we could set it to something concrete to have it persist.
77 » » » » c = SetMathRand(c, nil) 70 » » » c = SetMathRand(c, rand.New(rand.NewSource(now.UnixNano( ))))
78 » » » » r := rand.New(rand.NewSource(now.UnixNano())) 71 » » » r = rand.New(rand.NewSource(now.UnixNano()))
79 » » » » i := r.Int() 72 » » » So(GetMathRand(c).Int(), ShouldEqual, r.Int())
80 » » » » So(GetMathRand(c).Int(), ShouldEqual, i) 73 » » » So(GetMathRand(c).Int(), ShouldEqual, r.Int())
81 » » » » So(GetMathRand(c).Int(), ShouldEqual, i)
82 » » » })
83 }) 74 })
84 }) 75 })
85 } 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