本文整理汇总了Golang中gopkg/in/stretchr/testify/v1/assert.True函数的典型用法代码示例。如果您正苦于以下问题:Golang True函数的具体用法?Golang True怎么用?Golang True使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了True函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSelectQueryStruct
func TestSelectQueryStruct(t *testing.T) {
s := beginTxWithFixtures()
defer s.AutoRollback()
// Found:
var person Person
err := s.
Select("id", "name", "email").
From("people").
Where("email = $1", "[email protected]").
QueryStruct(&person)
assert.NoError(t, err)
assert.True(t, person.ID > 0)
assert.Equal(t, person.Name, "John")
assert.True(t, person.Email.Valid)
assert.Equal(t, person.Email.String, "[email protected]")
// Not found:
var person2 Person
err = s.
Select("id", "name", "email").
From("people").Where("email = $1", "[email protected]").
QueryStruct(&person2)
assert.Contains(t, err.Error(), "no rows")
}
示例2: TestCommitWithNestedNestedCommit
func TestCommitWithNestedNestedCommit(t *testing.T) {
log.Suppress(true)
defer log.Suppress(false)
installFixtures()
tx, err := testDB.Begin()
assert.NoError(t, err)
err = nestedNestedCommit(tx)
assert.NoError(t, err)
err = tx.Commit()
assert.NoError(t, err)
var person Person
err = testDB.
Select("*").
From("people").
Where("email = $1", "[email protected]").
QueryStruct(&person)
assert.NoError(t, err)
assert.True(t, person.ID > 0)
err = testDB.
Select("*").
From("people").
Where("email = $1", "[email protected]").
QueryStruct(&person)
assert.NoError(t, err)
assert.True(t, person.ID > 0)
}
示例3: TestCacheSelectQueryStruct
func TestCacheSelectQueryStruct(t *testing.T) {
Cache.FlushDB()
for i := 0; i < 2; i++ {
// Found:
var person Person
err := testDB.
Select("id", "name", "email").
From("people").
Where("email = $1", "[email protected]").
Cache("selectdoc.5", 1*time.Second, false).
QueryStruct(&person)
assert.NoError(t, err)
assert.True(t, person.ID > 0)
assert.Equal(t, person.Name, "John")
assert.True(t, person.Email.Valid)
assert.Equal(t, person.Email.String, "[email protected]")
// Not found:
var person2 Person
err = testDB.
Select("id", "name", "email").
From("people").Where("email = $1", "[email protected]").
Cache("selectdoc.6", 1*time.Second, false).
QueryStruct(&person2)
assert.Contains(t, err.Error(), "no rows")
}
}
示例4: TestQueryObject
func TestQueryObject(t *testing.T) {
s := beginTxWithFixtures()
defer s.AutoRollback()
var people jo.Object
err := s.
Select("id", "name", "email").
From("people").
OrderBy("id ASC").
QueryObject(&people)
assert.NoError(t, err)
assert.Equal(t, len(people.AsSlice(".")), 6)
// Make sure that the Ids are set. It's possible (maybe?) that different DBs set ids differently so
// don't assume they're 1 and 2.
assert.True(t, people.MustInt64("[0].id") > 0)
assert.True(t, people.MustInt64("[1].id") > people.MustInt64("[0].id"))
mario, _ := people.At("[0]")
john, _ := people.At("[1]")
assert.Equal(t, mario.MustString("name"), "Mario")
assert.Equal(t, mario.MustString("email"), "[email protected]")
assert.Equal(t, john.MustString("name"), "John")
assert.Equal(t, john.MustString("email"), "[email protected]")
}
示例5: TestCacheSelectQueryStructs
func TestCacheSelectQueryStructs(t *testing.T) {
Cache.FlushDB()
for i := 0; i < 2; i++ {
var people []Person
err := testDB.
Select("id", "name", "email").
From("people").
OrderBy("id ASC").
Cache("selectdoc.4", 1*time.Second, false).
QueryStructs(&people)
assert.NoError(t, err)
assert.Equal(t, len(people), 6)
// Make sure that the Ids are set. It's possible (maybe?) that different DBs set ids differently so
// don't assume they're 1 and 2.
assert.True(t, people[0].ID > 0)
assert.True(t, people[1].ID > people[0].ID)
assert.Equal(t, people[0].Name, "Mario")
assert.True(t, people[0].Email.Valid)
assert.Equal(t, people[0].Email.String, "[email protected]")
assert.Equal(t, people[1].Name, "John")
assert.True(t, people[1].Email.Valid)
assert.Equal(t, people[1].Email.String, "[email protected]")
}
}
示例6: TestInsect
func TestInsect(t *testing.T) {
// Insert by specifying values
s := beginTxWithFixtures()
defer s.AutoRollback()
var id int64
err := s.Insect("people").
Columns("name", "email").
Values("mario", "[email protected]").
Returning("id").
QueryScalar(&id)
assert.NoError(t, err)
assert.True(t, id > 0)
// Insert by specifying a record (ptr to struct)
person := Person{Name: "Barack"}
person.Email.Valid = true
person.Email.String = "[email protected]"
err = s.
Insect("people").
Columns("name", "email").
Record(&person).
Returning("id", "created_at").
QueryStruct(&person)
assert.NoError(t, err)
assert.True(t, person.ID > 0)
assert.NotEqual(t, person.CreatedAt, dat.NullTime{})
}
示例7: TestUpdateBlacklist
func TestUpdateBlacklist(t *testing.T) {
installFixtures()
// Insert by specifying a record (struct)
p := Person{Name: "Barack"}
p.Foo = "bar"
var foo string
var name string
var id int64
err := testDB.
InsertInto("people").
Whitelist("name", "foo").
Record(p).
Returning("id", "name", "foo").
QueryScalar(&id, &name, &foo)
assert.NoError(t, err)
assert.True(t, id > 0)
assert.Equal(t, name, "Barack")
assert.Equal(t, foo, "bar")
p2 := Person{Name: "oy"}
p2.Foo = "bah"
var name2 string
var foo2 string
err = testDB.
Update("people").
SetBlacklist(p2, "id", "name", "email", "key", "doc", "created_at").
Where("id = $1", id).
Returning("name", "foo").
QueryScalar(&name2, &foo2)
assert.NoError(t, err)
assert.True(t, id > 0)
assert.Equal(t, name2, "Barack")
assert.Equal(t, foo2, "bah")
}
示例8: TestSelectQueryStructs
func TestSelectQueryStructs(t *testing.T) {
s := beginTxWithFixtures()
defer s.AutoRollback()
var people []Person
err := s.
Select("id", "name", "email").
From("people").
OrderBy("id ASC").
QueryStructs(&people)
assert.NoError(t, err)
assert.Equal(t, len(people), 6)
// Make sure that the Ids are set. It's possible (maybe?) that different DBs set ids differently so
// don't assume they're 1 and 2.
assert.True(t, people[0].ID > 0)
assert.True(t, people[1].ID > people[0].ID)
assert.Equal(t, people[0].Name, "Mario")
assert.True(t, people[0].Email.Valid)
assert.Equal(t, people[0].Email.String, "[email protected]")
assert.Equal(t, people[1].Name, "John")
assert.True(t, people[1].Email.Valid)
assert.Equal(t, people[1].Email.String, "[email protected]")
// TODO: test map
}
示例9: TestDirSymlinkElementRelativePath
func TestDirSymlinkElementRelativePath(t *testing.T) {
e := createElement(dirSymlink, pwd)
assert.True(t, e.IsExists())
assert.False(t, e.IsDir())
assert.True(t, e.IsSymLink())
assert.Equal(t, filepath.Join(pwd, dirSymlink), e.Path())
assert.Equal(t, filepath.Dir(filepath.Join(pwd, dirSymlink)), e.Dirname())
}
示例10: TestDirSymlinkElementFullPath
func TestDirSymlinkElementFullPath(t *testing.T) {
fullPath := filepath.Join(pwd, dirSymlink)
e := createElement(fullPath, "/path/to/dummy")
assert.True(t, e.IsExists())
assert.False(t, e.IsDir())
assert.True(t, e.IsSymLink())
assert.Equal(t, fullPath, e.Path())
assert.Equal(t, filepath.Dir(fullPath), e.Dirname())
}
示例11: TestSelectDocDate
func TestSelectDocDate(t *testing.T) {
var comments []*Comment
err := testDB.SelectDoc("id", "comment", `created_at as "CreatedAt"`).
From("comments").
QueryStructs(&comments)
assert.NoError(t, err)
assert.True(t, comments[0].CreatedAt.Valid)
assert.True(t, comments[1].CreatedAt.Valid)
}
示例12: TestParallel
func TestParallel(t *testing.T) {
var result string
tasks := func(p *Project) {
p.Task1("A", func(*Context) {
result += "A"
})
p.Task1("B", func(*Context) {
time.Sleep(10 * time.Millisecond)
result += "B"
})
p.Task("C", nil, func(*Context) {
result += "C"
})
p.Task("D", nil, func(*Context) {
result += "D"
})
p.Task("default", P{"A", "B", "C", "D"}, nil)
}
argv := []string{}
ch := make(chan int)
go func() {
execCLI(tasks, argv, func(code int) {
assert.Equal(t, code, 0)
assert.True(t, len(result) == 4)
ch <- code
close(ch)
})
}()
<-ch
}
示例13: TestInsertBlacklist
func TestInsertBlacklist(t *testing.T) {
// type Person struct {
// ID int64 `db:"id"`
// Name string `db:"name"`
// Foo string `db:"foo"`
// Email dat.NullString `db:"email"`
// Key dat.NullString `db:"key"`
// Doc dat.NullString `db:"doc"`
// CreatedAt dat.NullTime `db:"created_at"`
// }
// Insert by specifying a record (struct)
person2 := Person{Name: "Barack"}
person2.Email.Valid = true
person2.Email.String = "[email protected]"
var email sql.NullString
var name string
var id int64
err := testDB.
InsertInto("people").
Blacklist("id", "foo", "email", "key", "doc", "created_at").
Record(person2).
Returning("id", "name", "email").
QueryScalar(&id, &name, &email)
assert.NoError(t, err)
assert.True(t, id > 0)
assert.False(t, email.Valid)
assert.Equal(t, name, "Barack")
}
示例14: TestInsertDoubleDollarQuote
func TestInsertDoubleDollarQuote(t *testing.T) {
s := beginTxWithFixtures()
defer s.AutoRollback()
expected := common.RandomString(16)
var str string
err := s.
InsertInto("people").
Columns("name", "key").
Values("test", expected).
Returning("key").
QueryScalar(&str)
assert.NoError(t, err)
assert.Equal(t, expected, str)
// ensure the tag cannot be escaped by user
oldDollarTag := postgres.GetPgDollarTag()
expected = common.RandomString(1024) + "'" + oldDollarTag
builder := s.
InsertInto("people").
Columns("name", "key").
Values("test", expected).
Returning("key")
sql, _, _ := builder.SetIsInterpolated(true).Interpolate()
assert.NotEqual(t, oldDollarTag, postgres.GetPgDollarTag())
assert.True(t, strings.Contains(sql, postgres.GetPgDollarTag()))
builder.QueryScalar(&str)
assert.NoError(t, err)
assert.Equal(t, expected, str)
}
示例15: TestNullInt64From
func TestNullInt64From(t *testing.T) {
v := int64(400)
n := NullInt64From(v)
assert.True(t, n.Valid)
assert.Equal(t, n.Int64, v)
}