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

Unified Diff: go/src/infra/gae/libs/wrapper/dummy_test.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Added coverage files. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | go/src/infra/gae/libs/wrapper/mathrand.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/wrapper/dummy_test.go
diff --git a/go/src/infra/gae/libs/wrapper/dummy_test.go b/go/src/infra/gae/libs/wrapper/dummy_test.go
index 9d4f101fb4a3de271b4477e1c2c332ed868497a3..61e8ab2c09228ee875d141a5982736c022460138 100644
--- a/go/src/infra/gae/libs/wrapper/dummy_test.go
+++ b/go/src/infra/gae/libs/wrapper/dummy_test.go
@@ -14,20 +14,19 @@ import (
"appengine/memcache"
. "github.com/smartystreets/goconvey/convey"
+ "infra/libs/clock/testclock"
)
func TestContextAccess(t *testing.T) {
Convey("Context Access", t, func() {
- c := context.Background()
+ now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
+ c, _ := testclock.UseTime(context.Background(), now)
Convey("blank", func() {
So(GetDS(c), ShouldBeNil)
So(GetMC(c), ShouldBeNil)
So(GetTQ(c), ShouldBeNil)
So(GetGI(c), ShouldBeNil)
-
- now := time.Now()
- So(GetTimeNow(c), ShouldHappenOnOrAfter, now)
})
Convey("DS", func() {
@@ -59,30 +58,19 @@ func TestContextAccess(t *testing.T) {
So(func() { q.Distinct() }, ShouldPanic)
})
- Convey("TimeNow", func() {
- thing := time.Date(2000, time.August, 20, 0, 0, 0, 0, time.UTC)
- c = SetTimeNow(c, &thing)
- So(GetTimeNow(c), ShouldResemble, thing)
-
- Convey("MathRand", func() {
- r := rand.New(rand.NewSource(thing.UnixNano()))
- i := r.Int()
+ Convey("MathRand", func() {
+ r := rand.New(rand.NewSource(now.UnixNano()))
+ i := r.Int()
- // when it's unset it picks TimeNow every time
- So(GetMathRand(c).Int(), ShouldEqual, i)
- So(GetMathRand(c).Int(), ShouldEqual, i)
+ // when it's unset it picks the current time every time
+ So(GetMathRand(c).Int(), ShouldEqual, i)
+ So(GetMathRand(c).Int(), ShouldEqual, i)
- // But we could set it to something concrete to have it persist.
- c = SetMathRand(c, rand.New(rand.NewSource(thing.UnixNano())))
- r = rand.New(rand.NewSource(thing.UnixNano()))
- So(GetMathRand(c).Int(), ShouldEqual, r.Int())
- So(GetMathRand(c).Int(), ShouldEqual, r.Int())
- })
-
- c = SetTimeNow(c, nil)
- now := time.Now()
- So(GetTimeNow(c), ShouldHappenOnOrAfter, now)
+ // But we could set it to something concrete to have it persist.
+ c = SetMathRand(c, rand.New(rand.NewSource(now.UnixNano())))
+ r = rand.New(rand.NewSource(now.UnixNano()))
+ So(GetMathRand(c).Int(), ShouldEqual, r.Int())
+ So(GetMathRand(c).Int(), ShouldEqual, r.Int())
})
-
})
}
« no previous file with comments | « no previous file | go/src/infra/gae/libs/wrapper/mathrand.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698