当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.True函数代码示例

本文整理汇总了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")
}
开发者ID:syreclabs,项目名称:dat,代码行数:25,代码来源:select_exec_test.go

示例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)
}
开发者ID:PlanitarInc,项目名称:dat,代码行数:28,代码来源:tx_test.go

示例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")
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:28,代码来源:cache_test.go

示例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]")
}
开发者ID:syreclabs,项目名称:dat,代码行数:26,代码来源:query_object_test.go

示例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]")
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:27,代码来源:cache_test.go

示例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{})
}
开发者ID:PlanitarInc,项目名称:dat,代码行数:29,代码来源:insect_test.go

示例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")
}
开发者ID:iPowow,项目名称:lbManager,代码行数:35,代码来源:update_exec_test.go

示例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
}
开发者ID:syreclabs,项目名称:dat,代码行数:28,代码来源:select_exec_test.go

示例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())
}
开发者ID:kumatch,项目名称:cpr,代码行数:9,代码来源:element_test.go

示例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())
}
开发者ID:kumatch,项目名称:cpr,代码行数:10,代码来源:element_test.go

示例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)
}
开发者ID:syreclabs,项目名称:dat,代码行数:11,代码来源:select_doc_test.go

示例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
}
开发者ID:coreroller,项目名称:coreroller,代码行数:31,代码来源:project_test.go

示例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")
}
开发者ID:syreclabs,项目名称:dat,代码行数:30,代码来源:insert_exec_test.go

示例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)
}
开发者ID:syreclabs,项目名称:dat,代码行数:32,代码来源:insert_exec_test.go

示例15: TestNullInt64From

func TestNullInt64From(t *testing.T) {
	v := int64(400)
	n := NullInt64From(v)

	assert.True(t, n.Valid)
	assert.Equal(t, n.Int64, v)
}
开发者ID:iPowow,项目名称:lbManager,代码行数:7,代码来源:types_test.go


注:本文中的gopkg/in/stretchr/testify/v1/assert.True函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。