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

Unified Diff: go/src/infra/libs/clock/testclock/context.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 | « go/src/infra/libs/clock/systemtimer_test.go ('k') | go/src/infra/libs/clock/testclock/testclock.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/libs/clock/testclock/context.go
diff --git a/go/src/infra/libs/clock/testclock/context.go b/go/src/infra/libs/clock/testclock/context.go
new file mode 100644
index 0000000000000000000000000000000000000000..9ea91fc2e30459cb27942831e7cc38f5732929ef
--- /dev/null
+++ b/go/src/infra/libs/clock/testclock/context.go
@@ -0,0 +1,20 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package testclock
+
+import (
+ "time"
+
+ "golang.org/x/net/context"
+ "infra/libs/clock"
+)
+
+// UseTime instantiates a TestClock and returns a Context that is configured to
+// use that clock, as well as the instantiated clock.
+func UseTime(ctx context.Context, now time.Time) (rctx context.Context, tc TestClock) {
+ tc = New(now)
+ rctx = clock.Set(ctx, tc)
+ return
+}
« no previous file with comments | « go/src/infra/libs/clock/systemtimer_test.go ('k') | go/src/infra/libs/clock/testclock/testclock.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698