| 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 gae | |
| 6 | |
| 7 import ( | |
| 8 "math/rand" | |
| 9 "testing" | |
| 10 "time" | |
| 11 | |
| 12 "golang.org/x/net/context" | |
| 13 | |
| 14 "github.com/luci/luci-go/common/clock/testclock" | |
| 15 | |
| 16 . "github.com/smartystreets/goconvey/convey" | |
| 17 ) | |
| 18 | |
| 19 func TestContextAccess(t *testing.T) { | |
| 20 Convey("Context Access", t, func() { | |
| 21 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) | |
| 22 c, _ := testclock.UseTime(context.Background(), now) | |
| 23 | |
| 24 Convey("blank", func() { | |
| 25 So(GetMC(c), ShouldBeNil) | |
| 26 So(GetTQ(c), ShouldBeNil) | |
| 27 So(GetGI(c), ShouldBeNil) | |
| 28 }) | |
| 29 | |
| 30 Convey("RDS", func() { | |
| 31 c = SetRDS(c, DummyRDS()) | |
| 32 So(GetRDS(c), ShouldNotBeNil) | |
| 33 So(func() { GetRDS(c).NewKey("", "", 1, nil) }, ShouldPa
nic) | |
| 34 }) | |
| 35 | |
| 36 Convey("MC", func() { | |
| 37 c = SetMC(c, DummyMC()) | |
| 38 So(GetMC(c), ShouldNotBeNil) | |
| 39 So(func() { GetMC(c).Add(nil) }, ShouldPanic) | |
| 40 }) | |
| 41 | |
| 42 Convey("TQ", func() { | |
| 43 c = SetTQ(c, DummyTQ()) | |
| 44 So(GetTQ(c), ShouldNotBeNil) | |
| 45 So(func() { GetTQ(c).Purge("") }, ShouldPanic) | |
| 46 }) | |
| 47 | |
| 48 Convey("GI", func() { | |
| 49 c = SetGI(c, DummyGI()) | |
| 50 So(GetGI(c), ShouldNotBeNil) | |
| 51 So(func() { GetGI(c).Datacenter() }, ShouldPanic) | |
| 52 }) | |
| 53 | |
| 54 Convey("QY", func() { | |
| 55 q := DummyQY() | |
| 56 So(func() { q.Distinct() }, ShouldPanic) | |
| 57 }) | |
| 58 | |
| 59 Convey("MathRand", func() { | |
| 60 // Note that the non-randomness below is because time is
fixed at the | |
| 61 // top of the outer test function. Normally it would evo
lve with time. | |
| 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 | |
| 69 Convey("set persistance", func() { | |
| 70 c = SetMathRand(c, rand.New(rand.NewSource(now.U
nixNano()))) | |
| 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 Convey("nil set", func() { | |
| 77 c = SetMathRand(c, nil) | |
| 78 r := rand.New(rand.NewSource(now.UnixNano())) | |
| 79 i := r.Int() | |
| 80 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 81 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 82 }) | |
| 83 }) | |
| 84 }) | |
| 85 } | |
| OLD | NEW |