本文整理汇总了Golang中github.com/coocood/assrt.Assert.MustZero方法的典型用法代码示例。如果您正苦于以下问题:Golang Assert.MustZero方法的具体用法?Golang Assert.MustZero怎么用?Golang Assert.MustZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coocood/assrt.Assert
的用法示例。
在下文中一共展示了Assert.MustZero方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DoTestSaveAndDelete
func DoTestSaveAndDelete(assert *assrt.Assert, info dialectInfo) {
x := time.Now()
assert.MustZero(x.Sub(x.UTC()))
now := time.Now()
mg, q := setupDb(assert, info)
type saveModel struct {
Id Id
A string
B int
Updated time.Time
Created time.Time
}
model1 := saveModel{
A: "banana",
B: 5,
}
model2 := saveModel{
A: "orange",
B: 4,
}
mg.dropTableIfExists(&model1)
mg.CreateTableIfNotExists(&model1)
affected, err := q.Save(&model1)
assert.MustNil(err)
assert.Equal(1, affected)
assert.True(model1.Created.Sub(now) > 0)
assert.True(model1.Updated.Sub(now) > 0)
// make sure created/updated values match the db
var model1r []*saveModel
err = q.Where("id = ?", model1.Id).FindAll(&model1r)
assert.MustNil(err)
assert.MustOneLen(model1r)
assert.Equal(model1.Created.Unix(), model1r[0].Created.Unix())
assert.Equal(model1.Updated.Unix(), model1r[0].Updated.Unix())
oldCreate := model1.Created
oldUpdate := model1.Updated
model1.A = "grape"
model1.B = 9
time.Sleep(time.Second * 1) // sleep for 1 sec
affected, err = q.Save(&model1)
assert.MustNil(err)
assert.MustEqual(1, affected)
assert.True(model1.Created.Equal(oldCreate))
assert.True(model1.Updated.Sub(oldUpdate) > 0)
// make sure created/updated values match the db
var model1r2 []*saveModel
err = q.Where("id = ?", model1.Id).FindAll(&model1r2)
assert.MustNil(err)
assert.MustOneLen(model1r2)
assert.True(model1r2[0].Updated.Sub(model1r2[0].Created) >= 1)
assert.Equal(model1.Created.Unix(), model1r2[0].Created.Unix())
assert.Equal(model1.Updated.Unix(), model1r2[0].Updated.Unix())
affected, err = q.Save(&model2)
assert.MustNil(err)
assert.Equal(1, affected)
affected, err = q.Delete(&model2)
assert.MustNil(err)
assert.Equal(1, affected)
}