本文整理汇总了Golang中github.com/coocood/assrt.Assert.Nil方法的典型用法代码示例。如果您正苦于以下问题:Golang Assert.Nil方法的具体用法?Golang Assert.Nil怎么用?Golang Assert.Nil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coocood/assrt.Assert
的用法示例。
在下文中一共展示了Assert.Nil方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DoTestTransaction
func DoTestTransaction(assert *assrt.Assert, info dialectInfo) {
mg, q := setupDb(assert, info)
defer mg.Close()
defer q.Close()
type txModel struct {
Id int64
A string
}
table := txModel{
A: "A",
}
mg.dropTableIfExists(&table)
mg.CreateTableIfNotExists(&table)
q.Begin()
assert.NotNil(q.Tx)
_, err := q.Save(&table)
assert.Nil(err)
err = q.Rollback()
assert.Nil(err)
out := new(txModel)
err = q.Find(out)
assert.Equal(sql.ErrNoRows, err)
q.Begin()
table.Id = 0
_, err = q.Save(&table)
assert.Nil(err)
err = q.Commit()
assert.Nil(err)
out.Id = table.Id
err = q.Find(out)
assert.Nil(err)
assert.Equal("A", out.A)
}
示例2: DoTestForeignKey
func DoTestForeignKey(assert *assrt.Assert, info dialectInfo) {
mg, q := setupDb(assert, info)
defer mg.Close()
defer q.Close()
type user struct {
Id int64
Name string
}
type post struct {
Id int64
Title string
AuthorId int64
Author *user
}
aUser := &user{
Name: "john",
}
aPost := &post{
Title: "A Title",
}
mg.dropTableIfExists(aPost)
mg.dropTableIfExists(aUser)
mg.CreateTableIfNotExists(aUser)
mg.CreateTableIfNotExists(aPost)
affected, err := q.Save(aUser)
assert.Nil(err)
aPost.AuthorId = int64(aUser.Id)
affected, err = q.Save(aPost)
assert.Equal(1, affected)
pst := new(post)
pst.Id = aPost.Id
err = q.Find(pst)
assert.MustNil(err)
assert.Equal(aPost.Id, pst.Id)
assert.Equal("john", pst.Author.Name)
pst.Author = nil
err = q.OmitFields("Author").Find(pst)
assert.MustNil(err)
assert.MustNil(pst.Author)
err = q.OmitJoin().Find(pst)
assert.MustNil(err)
assert.MustNil(pst.Author)
var psts []*post
err = q.FindAll(&psts)
assert.MustNil(err)
assert.OneLen(psts)
assert.Equal("john", psts[0].Author.Name)
}
示例3: DoTestForeignKey
func DoTestForeignKey(assert *assrt.Assert, info dialectInfo) {
mg, q := setupDb(assert, info)
type user struct {
Id Id
Name string
}
type post struct {
Id Id
Title string
AuthorId int64
Author *user
}
aUser := &user{
Name: "john",
}
aPost := &post{
Title: "A Title",
}
mg.dropTableIfExists(aPost)
mg.dropTableIfExists(aUser)
mg.CreateTableIfNotExists(aUser)
mg.CreateTableIfNotExists(aPost)
uid, err := q.Save(aUser)
assert.Nil(err)
aPost.AuthorId = int64(uid)
affected, err := q.Save(aPost)
assert.Equal(1, affected)
pst := new(post)
pst.Id = aPost.Id
err = q.Find(pst)
assert.MustNil(err)
assert.MustNotNil(pst)
assert.Equal(uid, pst.Id)
assert.Equal("john", pst.Author.Name)
}
示例4: DoTestFind
func DoTestFind(assert *assrt.Assert, info dialectInfo) {
mg, q := setupDb(assert, info)
now := time.Now()
type types struct {
Id Id
Str string
Intgr int64
Flt float64
Bytes []byte
Time time.Time
}
modelData := &types{
Str: "string!",
Intgr: -1,
Flt: 3.8,
Bytes: []byte("bytes!"),
Time: now,
}
mg.dropTableIfExists(modelData)
mg.CreateTableIfNotExists(modelData)
out := new(types)
condition := NewCondition("str = ?", "string!").And("intgr = ?", -1)
err := q.Condition(condition).Find(out)
assert.Nil(err)
assert.Zero(out.Id)
affected, err := q.Save(modelData)
assert.Nil(err)
assert.Equal(1, affected)
err = q.Condition(condition).Find(out)
assert.Nil(err)
assert.Equal(1, out.Id)
assert.Equal("string!", out.Str)
assert.Equal(-1, out.Intgr)
assert.Equal(3.8, out.Flt)
assert.Equal([]byte("bytes!"), out.Bytes)
diff := now.Sub(out.Time)
assert.True(diff < time.Second && diff > -time.Second)
modelData.Id = 5
modelData.Str = "New row"
_, err = q.Save(modelData)
assert.Nil(err)
out = new(types)
condition = NewCondition("str = ?", "New row").And("flt = ?", 3.8)
err = q.Condition(condition).Find(out)
assert.Nil(err)
assert.Equal(5, out.Id)
allOut := []*types{}
err = q.Where("intgr = ?", -1).FindAll(&allOut)
assert.Nil(err)
assert.Equal(2, len(allOut))
}