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


Golang assert.NoError函数代码示例

本文整理汇总了Golang中gopkg/in/stretchr/testify/v1/assert.NoError函数的典型用法代码示例。如果您正苦于以下问题:Golang NoError函数的具体用法?Golang NoError怎么用?Golang NoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestUpdateReturningStar

func TestUpdateReturningStar(t *testing.T) {
	s := beginTxWithFixtures()
	defer s.AutoRollback()

	// Insert a George
	var insertPerson Person
	err := s.InsertInto("people").Columns("name", "email").
		Values("George", "[email protected]").
		Returning("*").
		QueryStruct(&insertPerson)

	assert.NoError(t, err)
	assert.NotEmpty(t, insertPerson.ID)
	assert.Equal(t, insertPerson.Name, "George")
	assert.Equal(t, insertPerson.Email.Valid, true)
	assert.Equal(t, insertPerson.Email.String, "[email protected]")

	var updatePerson Person
	err = s.Update("people").
		Set("name", "Barack").
		Set("email", "[email protected]").
		Where("id = $1", insertPerson.ID).
		Returning("*").
		QueryStruct(&updatePerson)
	assert.NoError(t, err)
	assert.Equal(t, insertPerson.ID, updatePerson.ID)
	assert.Equal(t, updatePerson.Name, "Barack")
	assert.Equal(t, updatePerson.Email.Valid, true)
	assert.Equal(t, updatePerson.Email.String, "[email protected]")
}
开发者ID:iPowow,项目名称:lbManager,代码行数:30,代码来源:update_exec_test.go

示例2: 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

示例3: TestUpdateReal

func TestUpdateReal(t *testing.T) {
	s := beginTxWithFixtures()
	defer s.AutoRollback()

	var id int64
	// Insert a George
	s.InsertInto("people").Columns("name", "email").
		Values("George", "[email protected]").
		Returning("id").
		QueryScalar(&id)

	// Rename our George to Barack
	_, err := s.Update("people").SetMap(map[string]interface{}{"name": "Barack", "email": "[email protected]"}).Where("id = $1", id).Exec()

	assert.NoError(t, err)

	var person Person
	err = s.Select("*").From("people").Where("id = $1", id).QueryStruct(&person)
	assert.NoError(t, err)

	assert.Equal(t, person.ID, id)
	assert.Equal(t, person.Name, "Barack")
	assert.Equal(t, person.Email.Valid, true)
	assert.Equal(t, person.Email.String, "[email protected]")
}
开发者ID:iPowow,项目名称:lbManager,代码行数:25,代码来源:update_exec_test.go

示例4: TestCacheSelectQuerySliceByHash

func TestCacheSelectQuerySliceByHash(t *testing.T) {
	Cache.FlushDB()
	for i := 0; i < 2; i++ {
		var names []string
		err := testDB.
			Select("name").
			From("people").
			Cache("", 1*time.Second, false).
			QuerySlice(&names)

		assert.NoError(t, err)
		assert.Equal(t, len(names), 6)
		assert.Equal(t, names, []string{"Mario", "John", "Grant", "Tony", "Ester", "Reggie"})

		var ids []int64
		err = testDB.
			Select("id").
			From("people").
			Limit(1).
			Cache("", 1*time.Second, false).
			QuerySlice(&ids)

		assert.NoError(t, err)
		assert.Equal(t, len(ids), 1)
		assert.Equal(t, ids, []int64{1})
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:27,代码来源:cache_test.go

示例5: TestDeleteReal

func TestDeleteReal(t *testing.T) {
	s := beginTxWithFixtures()
	defer s.AutoRollback()

	var id int64
	// Insert a Barack
	s.InsertInto("people").
		Columns("name", "email").
		Values("Barack", "[email protected]").
		Returning("id").
		QueryScalar(&id)

	// Delete Barack
	res, err := s.DeleteFrom("people").Where("id = $1", id).Exec()
	assert.NoError(t, err)

	// Ensure we only reflected one row and that the id no longer exists
	assert.EqualValues(t, res.RowsAffected, 1)

	var count int64
	err = s.Select("count(*)").
		From("people").
		Where("id = $1", id).
		QueryScalar(&count)
	assert.NoError(t, err)
	assert.EqualValues(t, count, 0)
}
开发者ID:PlanitarInc,项目名称:dat,代码行数:27,代码来源:delete_exec_test.go

示例6: 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

示例7: TestTransactionReal

func TestTransactionReal(t *testing.T) {
	installFixtures()

	tx, err := testDB.Begin()
	assert.NoError(t, err)

	var id int64
	tx.InsertInto("people").Columns("name", "email").
		Values("Barack", "[email protected]").
		Returning("id").
		QueryScalar(&id)

	assert.True(t, id > 0)

	var person Person
	err = tx.
		Select("*").
		From("people").
		Where("id = $1", id).
		QueryStruct(&person)
	assert.NoError(t, err)

	assert.Equal(t, person.ID, id)
	assert.Equal(t, person.Name, "Barack")
	assert.Equal(t, person.Email.Valid, true)
	assert.Equal(t, person.Email.String, "[email protected]")

	err = tx.Commit()
	assert.NoError(t, err)
}
开发者ID:PlanitarInc,项目名称:dat,代码行数:30,代码来源:tx_test.go

示例8: 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

示例9: 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

示例10: TestLegacyIn

func TestLegacyIn(t *testing.T) {

	var cat = "cat"
	if isWindows {
		cat = "cmd /c type"
	}
	//// Run

	// in V2 BashOutput accepts an options map

	out, err := RunOutput(cat+" foo.txt", M{"$in": "test"})
	assert.NoError(t, err)
	assert.Equal(t, "foo", str.Clean(out))

	if isWindows {
		return
	}

	//// Bash

	// in V2 BashOutput accepts an options map
	out, err = BashOutput("cat foo.txt", M{"$in": "test"})
	assert.NoError(t, err)
	assert.Equal(t, "foo", str.Clean(out))
}
开发者ID:coreroller,项目名称:coreroller,代码行数:25,代码来源:project_test.go

示例11: TestUpdateKeywordColumnName

func TestUpdateKeywordColumnName(t *testing.T) {
	s := beginTxWithFixtures()
	defer s.AutoRollback()

	// Insert a user with a key
	res, err := s.
		InsertInto("people").
		Columns("name", "email", "key").
		Values("Benjamin", "[email protected]", "6").
		Exec()
	assert.NoError(t, err)

	// Update the key
	res, err = s.Update("people").Set("key", "6-revoked").Where(dat.Eq{"key": "6"}).Exec()
	assert.NoError(t, err)

	// Assert our record was updated (and only our record)
	assert.EqualValues(t, res.RowsAffected, 1)

	var person Person
	err = s.Select("*").From("people").Where(dat.Eq{"email": "[email protected].gov"}).QueryStruct(&person)
	assert.NoError(t, err)

	assert.Equal(t, person.Name, "Benjamin")
	assert.Equal(t, person.Key.String, "6-revoked")
}
开发者ID:iPowow,项目名称:lbManager,代码行数:26,代码来源:update_exec_test.go

示例12: TestCacheSelectQueryScalar

func TestCacheSelectQueryScalar(t *testing.T) {
	Cache.FlushDB()
	for i := 0; i < 2; i++ {

		var name string
		err := testDB.
			Select("name").
			From("people").
			Where("email = '[email protected]'").
			Cache("selectdoc.8", 1*time.Second, false).
			QueryScalar(&name)

		assert.NoError(t, err)
		assert.Equal(t, name, "John")

		var id int64
		err = testDB.
			Select("id").
			From("people").
			Limit(1).
			Cache("selectdoc.9", 1*time.Second, false).
			QueryScalar(&id)

		assert.NoError(t, err)
		assert.True(t, id > 0)
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:27,代码来源:cache_test.go

示例13: TestErrorInBeginIfRollbacked

func TestErrorInBeginIfRollbacked(t *testing.T) {
	log.Suppress(true)
	defer log.Suppress(false)
	installFixtures()
	tx, err := testDB.Begin()
	assert.NoError(t, err)
	err = tx.Rollback()
	assert.NoError(t, err)

	_, err = tx.Begin()
	assert.Exactly(t, ErrTxRollbacked, err)
}
开发者ID:PlanitarInc,项目名称:dat,代码行数:12,代码来源:tx_test.go

示例14: TestInterpolateInvalidNullTime

func TestInterpolateInvalidNullTime(t *testing.T) {
	now := time.Now()
	invalid := NullTime{pq.NullTime{Valid: false}}
	valid := NullTime{pq.NullTime{Time: now, Valid: true}}

	sql, _, err := Interpolate("SELECT * FROM foo WHERE valid = $1", []interface{}{valid})
	assert.NoError(t, err)

	assert.Equal(t, "SELECT * FROM foo WHERE valid = '"+valid.Time.Format(time.RFC3339Nano)+"'", sql)
	sql, _, err = Interpolate("SELECT * FROM foo WHERE invalid = $1", []interface{}{invalid})
	assert.NoError(t, err)
	assert.Equal(t, stripWS("SELECT * FROM foo WHERE invalid=NULL"), stripWS(sql))
}
开发者ID:JustinTulloss,项目名称:dat,代码行数:13,代码来源:interpolate_test.go

示例15: TestScalar

func TestScalar(t *testing.T) {
	s := beginTxWithFixtures()
	defer s.AutoRollback()

	var name string
	err := s.Select("name").From("people").Where("email = '[email protected]'").QueryScalar(&name)
	assert.NoError(t, err)
	assert.Equal(t, name, "John")

	var count int64
	err = s.Select("COUNT(*)").From("people").QueryScalar(&count)
	assert.NoError(t, err)
	assert.EqualValues(t, count, 6)
}
开发者ID:syreclabs,项目名称:dat,代码行数:14,代码来源:select_exec_test.go


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