本文整理汇总了Golang中testing.T.Before方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Before方法的具体用法?Golang T.Before怎么用?Golang T.Before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.Before方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_MessageEntry_MessagesIsStored_And_GetsCorrectParameters
func Test_MessageEntry_MessagesIsStored_And_GetsCorrectParameters(t *testing.T) {
defer initCtrl(t)()
a := assert.New(t)
startTime := time.Now()
msg := &guble.Message{Path: guble.Path("/topic1")}
var storedMsg []byte
var routedMsg *guble.Message
routerMock := NewMockMessageSink(ctrl)
messageEntry := NewMessageEntry(routerMock)
messageStoreMock := NewMockMessageStore(ctrl)
messageEntry.SetMessageStore(messageStoreMock)
messageStoreMock.EXPECT().StoreTx("topic1", gomock.Any()).
Do(func(topic string, callback func(msgId uint64) []byte) {
storedMsg = callback(uint64(42))
})
routerMock.EXPECT().HandleMessage(gomock.Any()).Do(func(msg *guble.Message) {
routedMsg = msg
a.Equal(uint64(42), msg.Id)
t, e := time.Parse(time.RFC3339, msg.PublishingTime) // publishing time
a.NoError(e)
a.True(t.After(startTime.Add(-1 * time.Second)))
a.True(t.Before(time.Now().Add(time.Second)))
})
messageEntry.HandleMessage(msg)
a.Equal(routedMsg.Bytes(), storedMsg)
}
示例2: TestTimes
// TestDimes tests the generation of durations and times.
func TestTimes(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
gen := audit.NewGenerator(audit.SimpleRand())
for i := 0; i < 10000; i++ {
// Test durations.
lo := gen.Duration(time.Second, time.Minute)
hi := gen.Duration(time.Second, time.Minute)
d := gen.Duration(lo, hi)
if hi < lo {
lo, hi = hi, lo
}
assert.True(lo <= d && d <= hi)
// Test times.
loc := time.Local
now := time.Now()
dur := gen.Duration(24*time.Hour, 30*24*time.Hour)
t := gen.Time(loc, now, dur)
assert.True(t.Equal(now) || t.After(now))
assert.True(t.Before(now.Add(dur)) || t.Equal(now.Add(dur)))
}
}