mirror of
https://github.com/golang/go.git
synced 2026-02-04 18:05:03 +03:00
synctest: fix comments for time.Now() in synctests
Also add a test case to make sure that time.Now() results in the documented date. Change-Id: Ic4cc577eba485b7c6e1a64122da06d7075bbe12e Reviewed-on: https://go-review.googlesource.com/c/go/+/685677 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Christian Höppner <hoeppi@google.com> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
committed by
Damien Neil
parent
63ec70d4e1
commit
aa5de9ebb5
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
start := time.Now() // always midnight UTC 2001-01-01
|
||||
start := time.Now() // always midnight UTC 2000-01-01
|
||||
go func() {
|
||||
time.Sleep(1 * time.Nanosecond)
|
||||
t.Log(time.Since(start)) // always logs "1ns"
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
//
|
||||
// func TestTime(t *testing.T) {
|
||||
// synctest.Test(t, func(t *testing.T) {
|
||||
// start := time.Now() // always midnight UTC 2001-01-01
|
||||
// start := time.Now() // always midnight UTC 2000-01-01
|
||||
// go func() {
|
||||
// time.Sleep(1 * time.Second)
|
||||
// t.Log(time.Since(start)) // always logs "1s"
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
"testing/synctest"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Tests for interactions between synctest bubbles and the testing package.
|
||||
@@ -179,3 +180,11 @@ func runTest(t *testing.T, args []string, f func(), pattern string) {
|
||||
t.Errorf("got output:\n%s\nwant matching:\n%s", out, pattern)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNow(t *testing.T) {
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
if got, want := time.Now(), time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC); !got.Equal(want) {
|
||||
t.Errorf("time.Now() = %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user