本文整理汇总了Golang中github.com/coocood/assrt.Assert.OneLen方法的典型用法代码示例。如果您正苦于以下问题:Golang Assert.OneLen方法的具体用法?Golang Assert.OneLen怎么用?Golang Assert.OneLen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coocood/assrt.Assert
的用法示例。
在下文中一共展示了Assert.OneLen方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: DoTestCreateTable
func DoTestCreateTable(assert *assrt.Assert, info dialectInfo) {
assert.Logf("Dialect %T\n", info.dialect)
mg, _ := setupDb(assert, info)
{
type AddColumn struct {
Prim Id
}
table := &AddColumn{}
mg.dropTableIfExists(table)
mg.CreateTableIfNotExists(table)
columns := mg.Dialect.ColumnsInTable(mg, table)
assert.OneLen(columns)
assert.True(columns["prim"])
}
table := &AddColumn{}
mg.CreateTableIfNotExists(table)
columns := mg.Dialect.ColumnsInTable(mg, table)
assert.Equal(4, len(columns))
}
示例3: DoTestCreateTable
func DoTestCreateTable(assert *assrt.Assert, info dialectInfo) {
assert.Logf("Dialect %T\n", info.dialect)
mg, _ := setupDb(assert, info)
defer mg.Close()
{
type AddColumn struct {
Prim int64 `qbs:"pk"`
}
table := &AddColumn{}
mg.dropTableIfExists(table)
mg.CreateTableIfNotExists(table)
columns := mg.Dialect.ColumnsInTable(mg, table)
assert.OneLen(columns)
assert.True(columns["prim"])
}
table := &AddColumn{}
mg.CreateTableIfNotExists(table)
assert.True(mg.Dialect.IndexExists(mg, "add_column", "add_column_first_last"))
columns := mg.Dialect.ColumnsInTable(mg, table)
assert.Equal(4, len(columns))
}