本文整理汇总了Golang中github.com/stretchr/testify/assert.WithinDuration函数的典型用法代码示例。如果您正苦于以下问题:Golang WithinDuration函数的具体用法?Golang WithinDuration怎么用?Golang WithinDuration使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithinDuration函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestKittychanInfoSource
func TestKittychanInfoSource(t *testing.T) {
f, err := os.Open("data/www.kittychan.info/information.html")
if err != nil {
t.Fatal(err)
}
defer f.Close()
source := NewKittychanInfoSource()
feed, err := source.ScrapeFromReader(f)
if err != nil {
t.Fatal(err)
}
loc, err := time.LoadLocation("Asia/Tokyo")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 100, len(feed.Items))
assert.Equal(t, "多摩センターイルミネーション\u3000今年も開催~キティちゃんのイルミネーション&オープニングセレモニーでキティちゃんのショー開催&キティちゃん達のパレードも~", feed.Items[0].Title)
assert.Equal(t, "http://www.tamacenter-cm.com/illumi/", feed.Items[0].Link.Href)
assert.WithinDuration(t, time.Date(2016, 11, 6, 0, 0, 0, 0, loc), feed.Items[0].Created, 0)
assert.Equal(t, "「Hello Kitty Japanダイバーシティ東京店」 リニューアルオープン", feed.Items[99].Title)
assert.Equal(t, "http://www.sanrio.co.jp/news/kt-gu-hkj-odaiba-renewal-20160921/", feed.Items[99].Link.Href)
assert.WithinDuration(t, time.Date(2016, 9, 21, 0, 0, 0, 0, loc), feed.Items[99].Created, 0)
}
开发者ID:mono0x,项目名称:my-scraper,代码行数:27,代码来源:kittychan_info_source_test.go
示例2: TestStartJob
func TestStartJob(t *testing.T) {
ts := NewTestServer()
defer ts.Close()
kc := New(ts.URL)
j := NewJobMap()
id, err := kc.CreateJob(j)
assert.NoError(t, err)
assert.NotEqual(t, id, "")
now := time.Now()
ok, err := kc.StartJob(id)
assert.NoError(t, err)
assert.True(t, ok)
// Wait let the job run
time.Sleep(time.Second * 1)
respJob, err := kc.GetJob(id)
assert.NoError(t, err)
assert.Equal(t, uint(1), respJob.Metadata.SuccessCount)
assert.WithinDuration(t, now, respJob.Metadata.LastSuccess, time.Second*2)
assert.WithinDuration(t, now, respJob.Metadata.LastAttemptedRun, time.Second*2)
cleanUp()
}
开发者ID:snowsnail,项目名称:kala,代码行数:26,代码来源:client_test.go
示例3: TestAfter
func TestAfter(t *testing.T) {
b := &SimpleBackoff{
Factor: 2,
Min: 100 * time.Millisecond,
Max: 2 * time.Second,
MaxAttempts: 1,
}
var t1, t2, t3 time.Time
var err1, err2 error
t1 = time.Now()
select {
case err1 = <-After(b):
t2 = time.Now()
case <-time.After(101 * time.Millisecond):
t.Error("Not executed on time")
}
select {
case err2 = <-After(b):
case <-time.After(time.Millisecond):
t.Error("Not executed on time")
}
t3 = time.Now()
assert.WithinDuration(t, t1.Add(100*time.Millisecond), t2, time.Millisecond)
assert.WithinDuration(t, t2, t3, time.Millisecond)
assert.Nil(t, err1)
assert.NotNil(t, err2)
}
开发者ID:dnaeon,项目名称:goback,代码行数:28,代码来源:goback_test.go
示例4: TestKalaStats
func TestKalaStats(t *testing.T) {
cache := NewMockCache()
for i := 0; i < 5; i++ {
j := GetMockJobWithGenericSchedule()
j.Init(cache)
j.Run(cache)
}
now := time.Now()
for i := 0; i < 5; i++ {
j := GetMockJobWithGenericSchedule()
j.Init(cache)
j.Disable()
}
kalaStat := NewKalaStats(cache)
createdAt := time.Now()
nextRunAt := time.Now().Add(
time.Duration(time.Minute * 5),
)
assert.Equal(t, kalaStat.Jobs, 10)
assert.Equal(t, kalaStat.ActiveJobs, 5)
assert.Equal(t, kalaStat.DisabledJobs, 5)
assert.Equal(t, kalaStat.SuccessCount, uint(5))
assert.Equal(t, kalaStat.ErrorCount, uint(0))
assert.WithinDuration(t, kalaStat.NextRunAt, nextRunAt, time.Second)
assert.WithinDuration(t, kalaStat.LastAttemptedRun, now, time.Millisecond*100)
assert.WithinDuration(t, kalaStat.CreatedAt, createdAt, time.Millisecond*100)
}
开发者ID:nivertech,项目名称:kala,代码行数:30,代码来源:jobstats_test.go
示例5: TestStateUpdateCheckWait
func TestStateUpdateCheckWait(t *testing.T) {
cws := NewUpdateCheckWaitState()
// no update
var tstart, tend time.Time
tstart = time.Now()
s, c := cws.Handle(nil, &stateTestController{
pollIntvl: 100 * time.Millisecond,
})
tend = time.Now()
assert.IsType(t, &UpdateCheckState{}, s)
assert.False(t, c)
assert.WithinDuration(t, tend, tstart, 105*time.Millisecond)
// asynchronously cancel state operation
go func() {
c := cws.Cancel()
assert.True(t, c)
}()
// should finish right away
tstart = time.Now()
s, c = cws.Handle(nil, &stateTestController{
pollIntvl: 100 * time.Millisecond,
})
tend = time.Now()
// canceled state should return itself
assert.IsType(t, &UpdateCheckWaitState{}, s)
assert.True(t, c)
assert.WithinDuration(t, tend, tstart, 5*time.Millisecond)
}
开发者ID:pasinskim,项目名称:mender,代码行数:31,代码来源:state_test.go
示例6: TestDependentJobs
func TestDependentJobs(t *testing.T) {
db := GetBoltDB(testDbPath)
cache := NewMemoryJobCache(db, time.Second*5)
mockJob := GetMockJobWithGenericSchedule()
mockJob.Name = "mock_parent_job"
mockJob.Init(cache)
mockChildJob := GetMockJob()
mockChildJob.ParentJobs = []string{
mockJob.Id,
}
mockChildJob.Init(cache)
assert.Equal(t, mockJob.DependentJobs[0], mockChildJob.Id)
assert.True(t, len(mockJob.DependentJobs) == 1)
j, err := cache.Get(mockJob.Id)
assert.NoError(t, err)
assert.Equal(t, j.DependentJobs[0], mockChildJob.Id)
j.Run(cache)
time.Sleep(time.Second * 2)
n := time.Now()
assert.WithinDuration(t, mockChildJob.LastAttemptedRun, n, 4*time.Second)
assert.WithinDuration(t, mockChildJob.LastSuccess, n, 4*time.Second)
db.Close()
}
开发者ID:nivertech,项目名称:kala,代码行数:30,代码来源:job_test.go
示例7: TestSanrioNewsReleaseSource
func TestSanrioNewsReleaseSource(t *testing.T) {
f, err := os.Open("data/www.sanrio.co.jp/corporate/release/index.html")
if err != nil {
t.Fatal(err)
}
defer f.Close()
doc, err := goquery.NewDocumentFromReader(f)
if err != nil {
t.Fatal(err)
}
loc, err := time.LoadLocation("Asia/Tokyo")
if err != nil {
t.Fatal(err)
}
source := NewSanrioNewsReleaseSource()
feed, err := source.ScrapeFromDocument(doc)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 51, len(feed.Items))
assert.Equal(t, "ぐでぐでやる気のない「ぐでたま」のイベント九州初上陸! 夏休み企画 「ぐでたま in ふくおか」 7月21日(木)〜 福岡パルコ & sanrio vivitix 天神地下街店にて開催 (PDF)", feed.Items[0].Title)
assert.Equal(t, "http://www.sanrio.co.jp/wp-content/uploads/2015/05/20160708-1.pdf", feed.Items[0].Link.Href)
assert.WithinDuration(t, time.Date(2016, 7, 8, 0, 0, 0, 0, loc), feed.Items[0].Created, 0)
assert.Equal(t, "2016年バレンタイン向けスペシャルギフト「GODIVA &ハローキティ」・「GODIVA &マイメロディ」1月6日(水)よりサンリオ限定販売", feed.Items[50].Title)
assert.Equal(t, "http://www.sanrio.co.jp/corporate/release/y2016/d0106/", feed.Items[50].Link.Href)
assert.WithinDuration(t, time.Date(2016, 1, 6, 0, 0, 0, 0, loc), feed.Items[50].Created, 0)
}
开发者ID:mono0x,项目名称:my-scraper,代码行数:30,代码来源:sanrio_news_release_source_test.go
示例8: TestSetDataSetsMeta
// TestSetDataSetsMeta tests that...yeah
func TestSetDataSetsMeta(t *testing.T) {
sts := SimpleTestSetup{
NamespaceName: "TestSetDataSetsMeta",
WorkSpecName: "spec",
}
sts.SetUp(t)
defer sts.TearDown(t)
meta, err := sts.WorkSpec.Meta(false)
if assert.NoError(t, err) {
assert.Equal(t, 0, meta.Priority)
assert.Equal(t, 20, meta.Weight)
assert.False(t, meta.Paused)
assert.False(t, meta.Continuous)
assert.False(t, meta.CanBeContinuous)
assert.Zero(t, meta.Interval)
assert.WithinDuration(t, time.Time{}, meta.NextContinuous, 1*time.Microsecond)
assert.Equal(t, 0, meta.MaxRunning)
assert.Equal(t, 0, meta.MaxAttemptsReturned)
assert.Equal(t, "", meta.NextWorkSpecName)
assert.Equal(t, 0, meta.AvailableCount)
assert.Equal(t, 0, meta.PendingCount)
assert.Equal(t, "", meta.Runtime)
}
err = sts.WorkSpec.SetData(map[string]interface{}{
"name": "spec",
"min_gb": 1,
"priority": 10,
"weight": 100,
"disabled": true,
"continuous": true,
"interval": 60,
"max_running": 10,
"max_getwork": 1,
"then": "spec2",
"runtime": "go",
})
assert.NoError(t, err)
meta, err = sts.WorkSpec.Meta(false)
if assert.NoError(t, err) {
assert.Equal(t, 10, meta.Priority)
assert.Equal(t, 100, meta.Weight)
assert.True(t, meta.Paused)
assert.True(t, meta.Continuous)
assert.True(t, meta.CanBeContinuous)
assert.Equal(t, 60*time.Second, meta.Interval)
assert.WithinDuration(t, time.Time{}, meta.NextContinuous, 1*time.Microsecond)
assert.Equal(t, 10, meta.MaxRunning)
assert.Equal(t, 1, meta.MaxAttemptsReturned)
assert.Equal(t, "spec2", meta.NextWorkSpecName)
assert.Equal(t, 0, meta.AvailableCount)
assert.Equal(t, 0, meta.PendingCount)
assert.Equal(t, "go", meta.Runtime)
}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:58,代码来源:work_spec.go
示例9: TestStateCancellable
func TestStateCancellable(t *testing.T) {
cs := NewCancellableState(BaseState{
id: MenderStateAuthorizeWait,
})
assert.Equal(t, MenderStateAuthorizeWait, cs.Id())
var s State
var c bool
// no update
var tstart, tend time.Time
tstart = time.Now()
s, c = cs.StateAfterWait(bootstrappedState, initState,
100*time.Millisecond)
tend = time.Now()
// not cancelled should return the 'next' state
assert.Equal(t, bootstrappedState, s)
assert.False(t, c)
assert.WithinDuration(t, tend, tstart, 105*time.Millisecond)
// asynchronously cancel state operation
go func() {
c := cs.Cancel()
assert.True(t, c)
}()
// should finish right away
tstart = time.Now()
s, c = cs.StateAfterWait(bootstrappedState, initState,
100*time.Millisecond)
tend = time.Now()
// canceled should return the other state
assert.Equal(t, initState, s)
assert.True(t, c)
assert.WithinDuration(t, tend, tstart, 5*time.Millisecond)
// same thing again, but calling Wait() now
go func() {
c := cs.Cancel()
assert.True(t, c)
}()
// should finish right away
tstart = time.Now()
wc := cs.Wait(100 * time.Millisecond)
tend = time.Now()
assert.False(t, wc)
assert.WithinDuration(t, tend, tstart, 5*time.Millisecond)
// let wait finish
tstart = time.Now()
wc = cs.Wait(100 * time.Millisecond)
tend = time.Now()
assert.True(t, wc)
assert.WithinDuration(t, tend, tstart, 105*time.Millisecond)
}
开发者ID:pasinskim,项目名称:mender,代码行数:56,代码来源:state_test.go
示例10: TestIntervalSMS
func TestIntervalSMS(t *testing.T) {
now := Now()
tests := []struct {
start, finish time.Time
msgs []string
}{
{now, now.Add(3 * time.Minute), []string{
"Message 0", "Message 1", "Message 2",
}},
}
for _, test := range tests {
rems, err := IntervalSMS("0123456789", test.msgs, test.start, test.finish)
if err != nil {
t.Errorf("Error from IntervalSMS: %v", err)
continue
}
// Every reminder should be scheduled within window (between
// start and finish)
for i, rem := range rems {
t.Logf("rem[%d] == %#v\n", i, rem)
assert.WithinDuration(t,
test.start,
rem.NextRun,
test.finish.Sub(test.start),
fmt.Sprintf(
"Reminder scheduled for %s, should be between %s and %s",
rem.NextRun, test.start, test.finish))
}
oneChunk := test.finish.Sub(test.start) / time.Duration(len(test.msgs))
t.Logf("oneChunk == %v", oneChunk)
// Each pair of messages should be at most oneChunk*2 apart
for i := 0; i < len(rems)-1; i++ {
// Adjacent reminders _should_ be closer than oneChunk * 2
assert.WithinDuration(
t,
rems[i].NextRun,
rems[i+1].NextRun,
oneChunk*time.Duration(2),
fmt.Sprintf("Reminders %v and %v scheduled too far apart (%v)",
rems[i],
rems[i+1],
time.Duration(2)*rems[i+1].NextRun.Sub(rems[i].NextRun)),
)
}
}
}
开发者ID:elimisteve,项目名称:do_reminder,代码行数:56,代码来源:interval_test.go
示例11: TestGetValidUser
func (suite *UserStoreSuite) TestGetValidUser() {
u, err := suite.store.Get(suite.user.Email)
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), suite.user.Email, u.Email)
assert.Equal(suite.T(), suite.user.Password, u.Password)
assert.Equal(suite.T(), suite.user.Salt, u.Salt)
assert.WithinDuration(suite.T(), suite.user.Updated, u.Updated, 1*time.Second)
assert.WithinDuration(suite.T(), suite.user.Created, u.Created, 1*time.Second)
}
开发者ID:plants,项目名称:sesame,代码行数:11,代码来源:persistence_test.go
示例12: TestTime
func TestTime(t *testing.T) {
p, _ := time.Parse(time.RFC3339Nano, "2011-08-18T19:03:37.000000000+01:00")
data := []struct {
in string
out time.Time
str string
}{
{"2014-12-15T08:00:00.000Z", time.Date(2014, 12, 15, 8, 0, 0, 0, time.UTC), "2014-12-15T08:00:00.000Z"},
{"2011-08-18T19:03:37.000000000+01:00", time.Date(2011, 8, 18, 19, 3, 37, 0, p.Location()), "2011-08-18T19:03:37.000+01:00"},
{"2014-12-15T19:30:20Z", time.Date(2014, 12, 15, 19, 30, 20, 0, time.UTC), "2014-12-15T19:30:20.000Z"},
}
for _, example := range data {
parsed, err := ParseDateTime(example.in)
assert.NoError(t, err)
assert.Equal(t, example.out.String(), parsed.Time.String(), "Failed to parse "+example.in)
assert.Equal(t, example.str, parsed.String())
mt, err := parsed.MarshalText()
assert.NoError(t, err)
assert.Equal(t, []byte(example.str), mt)
pp := DateTime{}
err = pp.UnmarshalText(mt)
assert.NoError(t, err)
assert.Equal(t, example.out.String(), pp.Time.String())
pp = DateTime{}
err = pp.Scan(example.in)
assert.NoError(t, err)
assert.Equal(t, DateTime{example.out}, pp)
}
_, err := ParseDateTime("yada")
assert.Error(t, err)
parsed, err := ParseDateTime("")
assert.NoError(t, err)
assert.WithinDuration(t, time.Unix(0, 0), parsed.Time, 0)
pp := DateTime{}
err = pp.UnmarshalText([]byte{})
assert.NoError(t, err)
assert.WithinDuration(t, time.Unix(0, 0), pp.Time, 0)
err = pp.UnmarshalText([]byte("yada"))
assert.Error(t, err)
pp = DateTime{}
err = pp.UnmarshalText([]byte(nil))
assert.NoError(t, err)
assert.WithinDuration(t, time.Unix(0, 0), pp.Time, 0)
err = pp.UnmarshalText([]byte("yada"))
assert.Error(t, err)
}
开发者ID:aleksandr-vin,项目名称:go-swagger,代码行数:53,代码来源:time_test.go
示例13: testBasic
func testBasic(t *testing.T, store data.Store) {
assert := assert.New(t)
var users = store.Collection("users")
assert.NotNil(users)
// testing basic CRUD operations
var bob = User{
Name: "bob",
Email: "[email protected]",
Age: 20,
}
var err = users.Insert(&bob)
ok(t, "insert", err)
if len(bob.ID) == 0 {
t.Error("ID is not set")
t.FailNow()
}
count, err := users.Count()
ok(t, "count", err)
assert.Equal(int64(1), count)
var now = time.Now().UTC()
assert.WithinDuration(now, bob.CreatedAt, 500*time.Millisecond, "created_at is not set")
assert.WithinDuration(now, bob.UpdatedAt, 500*time.Millisecond, "updated_at is not set")
var usr User
err = users.Get(bob.ID, &usr)
ok(t, "get", err)
assertUser(t, bob, usr)
bob.Name = "rob"
bob.Email = "[email protected]"
err = users.Update(bob.ID, &bob)
ok(t, "update", err)
err = users.Get(bob.ID, &usr)
ok(t, "get", err)
assertUser(t, bob, usr)
err = users.Delete(bob.ID)
ok(t, "delete", err)
count, err = users.Count()
ok(t, "count", err)
assert.Equal(int64(0), count)
}
开发者ID:gocontrib,项目名称:nosql,代码行数:52,代码来源:store_test.go
示例14: TestJobRun
func TestJobRun(t *testing.T) {
cache := NewMockCache()
j := GetMockJobWithGenericSchedule()
j.Init(cache)
j.Run(cache)
now := time.Now()
assert.Equal(t, j.SuccessCount, uint(1))
assert.WithinDuration(t, j.LastSuccess, now, 2*time.Second)
assert.WithinDuration(t, j.LastAttemptedRun, now, 2*time.Second)
}
开发者ID:nivertech,项目名称:kala,代码行数:13,代码来源:job_test.go
示例15: TestDependentJobsTwoParentsSameChild
// Two Parents with the same child
func TestDependentJobsTwoParentsSameChild(t *testing.T) {
cache := NewMockCache()
mockJobOne := GetMockJobWithGenericSchedule()
mockJobOne.Name = "mock_parent_one"
mockJobOne.Init(cache)
mockJobTwo := GetMockJobWithGenericSchedule()
mockJobTwo.Name = "mock_parent_two"
mockJobTwo.Init(cache)
mockChildJob := GetMockJob()
mockChildJob.Name = "mock_child"
mockChildJob.ParentJobs = []string{
mockJobOne.Id,
mockJobTwo.Id,
}
mockChildJob.Init(cache)
// Check that it gets placed in the array.
assert.Equal(t, mockJobOne.DependentJobs[0], mockChildJob.Id)
assert.Equal(t, mockJobTwo.DependentJobs[0], mockChildJob.Id)
assert.True(t, len(mockJobOne.DependentJobs) == 1)
assert.True(t, len(mockJobTwo.DependentJobs) == 1)
parentOne, err := cache.Get(mockJobOne.Id)
assert.NoError(t, err)
parentTwo, err := cache.Get(mockJobTwo.Id)
assert.NoError(t, err)
// Check that we can still get it from the cache.
assert.Equal(t, parentOne.DependentJobs[0], mockChildJob.Id)
assert.Equal(t, parentTwo.DependentJobs[0], mockChildJob.Id)
assert.True(t, len(parentOne.DependentJobs) == 1)
assert.True(t, len(parentTwo.DependentJobs) == 1)
parentOne.Run(cache)
time.Sleep(time.Second)
n := time.Now()
// TODO use abtime
assert.WithinDuration(t, parentOne.LastAttemptedRun, n, 3*time.Second)
assert.WithinDuration(t, parentOne.LastSuccess, n, 3*time.Second)
assert.WithinDuration(t, mockChildJob.LastAttemptedRun, n, 3*time.Second)
assert.WithinDuration(t, mockChildJob.LastSuccess, n, 3*time.Second)
assert.True(t, parentTwo.LastAttemptedRun.IsZero())
assert.True(t, parentTwo.LastSuccess.IsZero())
// TODO use abtime
time.Sleep(time.Second * 3)
parentTwo.Run(cache)
time.Sleep(time.Second)
n = time.Now()
// TODO use abtime
assert.WithinDuration(t, parentTwo.LastAttemptedRun, n, 3*time.Second)
assert.WithinDuration(t, parentTwo.LastSuccess, n, 3*time.Second)
assert.WithinDuration(t, mockChildJob.LastAttemptedRun, n, 3*time.Second)
assert.WithinDuration(t, mockChildJob.LastSuccess, n, 3*time.Second)
}
开发者ID:firnsan,项目名称:kala,代码行数:61,代码来源:job_test.go
示例16: TestDefaultMeta
// TestDefaultMeta tests that WorkSpec.Meta gets the correct defaults,
// which in a couple of cases are not zero values.
func TestDefaultMeta(t *testing.T) {
sts := SimpleTestSetup{
NamespaceName: "TestDefaultMeta",
WorkSpecName: "spec",
}
sts.SetUp(t)
defer sts.TearDown(t)
meta, err := sts.WorkSpec.Meta(false)
if assert.NoError(t, err) {
assert.Equal(t, 0, meta.Priority)
assert.Equal(t, 20, meta.Weight)
assert.False(t, meta.Paused)
assert.False(t, meta.Continuous)
assert.False(t, meta.CanBeContinuous)
assert.Zero(t, meta.Interval)
assert.WithinDuration(t, time.Time{}, meta.NextContinuous, 1*time.Microsecond)
assert.Equal(t, 0, meta.MaxRunning)
assert.Equal(t, 0, meta.MaxAttemptsReturned)
assert.Equal(t, "", meta.NextWorkSpecName)
assert.Equal(t, 0, meta.AvailableCount)
assert.Equal(t, 0, meta.PendingCount)
assert.Equal(t, "", meta.Runtime)
}
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:27,代码来源:work_spec.go
示例17: test
func (check *Check) test(t *testing.T, expect_out string, expect_rc int, message string) {
if message == "" {
message = "test_check"
}
os.Chmod(check.cmd_args[0], 0755)
err := check.Spawn()
if !assert.True(t, check.running, "%s: check.running is true post-spawn", message) {
t.Fatalf("Couldn't spawn check, bailing out: %s", err.Error())
}
assert.NoError(t, err, "%s: no errors on successful spawning of check", message)
assert.NotNil(t, check.process, "%s: check has a process", message)
assert.WithinDuration(t, time.Now(), check.started_at, 1*time.Second,
"%s check started within 1 second from now", message)
assert.Equal(t, check.ended_at, time.Time{}, "%s: check has no end time (yet)", message)
assert.False(t, check.sig_term, "%s: check has not been sigtermed", message)
assert.False(t, check.sig_kill, "%s: check has not been sigkilled", message)
var finished bool
for i := 0; i < 100; i++ {
finished = check.Reap()
if finished {
break
}
time.Sleep(100 * time.Millisecond)
assert.Equal(t, "", check.output, "%s: check has no output yet")
}
assert.True(t, finished, "%s: check finished", message)
assert.Equal(t, expect_out, check.output, "%s: check output was as expected", message)
assert.Equal(t, expect_rc, check.rc, "%s: check rc was as expected", message)
assert.False(t, check.running, "%s: check is no longer running", message)
}
开发者ID:qanx,项目名称:bmad,代码行数:32,代码来源:checks_test.go
示例18: TestGetJob
func TestGetJob(t *testing.T) {
testJob := testJobs[0]
// Expect a HGET operation to be preformed with the job hash key and job ID
conn.Command("HGET", HashKey, testJob.Job.Id).
Expect(testJob.Bytes).
ExpectError(nil)
storedJob, err := db.Get(testJob.Job.Id)
assert.Nil(t, err)
assert.WithinDuration(t, storedJob.NextRunAt, testJob.Job.NextRunAt, 100*time.Microsecond)
assert.Equal(t, testJob.Job.Name, storedJob.Name)
assert.Equal(t, testJob.Job.Id, storedJob.Id)
assert.Equal(t, testJob.Job.Command, storedJob.Command)
assert.Equal(t, testJob.Job.Schedule, storedJob.Schedule)
assert.Equal(t, testJob.Job.Owner, storedJob.Owner)
assert.Equal(t, testJob.Job.Metadata.SuccessCount, storedJob.Metadata.SuccessCount)
// Test error handling
conn.Command("HGET", HashKey, testJob.Job.Id).
ExpectError(errors.New("Redis error"))
storedJob, err = db.Get(testJob.Job.Id)
assert.NotNil(t, err)
}
开发者ID:snowsnail,项目名称:kala,代码行数:26,代码来源:redis_test.go
示例19: TestValuePressSource
func TestValuePressSource(t *testing.T) {
f, err := os.Open("data/www.value-press.com/search")
if err != nil {
t.Fatal(err)
}
defer f.Close()
source := NewValuePressSource()
feed, err := source.ScrapeFromReader(f)
if err != nil {
t.Fatal(err)
}
loc, err := time.LoadLocation("Asia/Tokyo")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 20, len(feed.Items))
assert.Equal(t, "ハローキティも出演!世界初!お皿に盛りつけられたコスメを使って楽しむ参加型メイクアップレッスンショー『ミワンダフルのメイクアップレストラン』が開催", feed.Items[0].Title)
assert.Equal(t, "https://www.value-press.com/pressrelease/171658", feed.Items[0].Link.Href)
assert.Equal(t, "メイクスマイルプロジェクト所属のメイクスマイルアーティスト・ミワンダフルがお届けする、参加型メイクアップレッスンショー『ミワンダフルのメイクアップレストラン』が2016年11月22(火)、 23日(水・祝)に原宿クエストホールにてオープンします。", feed.Items[0].Description)
assert.Equal(t, "メイクスマイルプロジェクト", feed.Items[0].Author.Name)
assert.WithinDuration(t, time.Date(2016, 10, 17, 10, 0, 0, 0, loc), feed.Items[0].Created, 0)
}
开发者ID:mono0x,项目名称:my-scraper,代码行数:25,代码来源:value_press_source_test.go
示例20: TestGetJobStats
func TestGetJobStats(t *testing.T) {
ts := NewTestServer()
defer ts.Close()
kc := New(ts.URL)
j := NewJobMap()
// Create the job
id, err := kc.CreateJob(j)
assert.NoError(t, err)
// Start the job
ok, err := kc.StartJob(id)
now := time.Now()
assert.NoError(t, err)
assert.True(t, ok)
// Wait let the job run
time.Sleep(time.Second * 1)
stats, err := kc.GetJobStats(id)
assert.NoError(t, err)
assert.Equal(t, id, stats[0].JobId)
assert.Equal(t, uint(0), stats[0].NumberOfRetries)
assert.True(t, stats[0].Success)
assert.True(t, stats[0].ExecutionDuration != time.Duration(0))
assert.WithinDuration(t, now, stats[0].RanAt, time.Second)
cleanUp()
}
开发者ID:snowsnail,项目名称:kala,代码行数:27,代码来源:client_test.go
注:本文中的github.com/stretchr/testify/assert.WithinDuration函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论