本文整理匯總了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)))
}
}