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


Golang Assert.Equal方法代码示例

本文整理汇总了Golang中github.com/coocood/assrt.Assert.Equal方法的典型用法代码示例。如果您正苦于以下问题:Golang Assert.Equal方法的具体用法?Golang Assert.Equal怎么用?Golang Assert.Equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/coocood/assrt.Assert的用法示例。


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

示例1: DoTestCreateIndexSql

func DoTestCreateIndexSql(assert *assrt.Assert, info dialectSyntax) {
	assert.Logf("Dialect %T\n", info.dialect)
	sql := info.dialect.CreateIndexSql("iname", "itable", true, "a", "b", "c")
	assert.Equal(info.createUniqueIndexSql, sql)
	sql = info.dialect.CreateIndexSql("iname2", "itable2", false, "d", "e")
	assert.Equal(info.createIndexSql, sql)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:7,代码来源:dialect_test.go

示例2: DoTestTransaction

func DoTestTransaction(assert *assrt.Assert, info dialectInfo) {
	mg, q := setupDb(assert, info)
	type txModel struct {
		Id Id
		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.Nil(err)
	assert.Zero(out.Id)
	q.Begin()
	table.Id = 0
	_, err = q.Save(&table)
	assert.Nil(err)
	err = q.Commit()
	assert.Nil(err)
	err = q.Find(out)
	assert.Nil(err)
	assert.Equal("A", out.A)
}
开发者ID:cgolang,项目名称:qbs,代码行数:31,代码来源:qbs_test.go

示例3: DoTestDeleteSQL

func DoTestDeleteSQL(assert *assrt.Assert, info dialectSyntax) {
	assert.Logf("Dialect %T\n", info.dialect)
	model := structPtrToModel(sqlGenSampleData, true, nil)
	criteria := &Criteria{model: model}
	criteria.mergePkCondition(info.dialect)
	sql, _ := info.dialect.DeleteSql(criteria)
	sql = info.dialect.SubstituteMarkers(sql)
	assert.Equal(info.deleteSql, sql)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:9,代码来源:dialect_test.go

示例4: DoTestValidation

func DoTestValidation(assert *assrt.Assert, info dialectInfo) {
	mg, q := setupDb(assert, info)
	valid := new(ValidatorTable)
	mg.dropTableIfExists(valid)
	mg.CreateTableIfNotExists(valid)
	valid.Name = "ok"
	q.Save(valid)
	valid.Id = 0
	_, err := q.Save(valid)
	assert.MustNotNil(err)
	assert.Equal("name already taken", err.Error())
}
开发者ID:cgolang,项目名称:qbs,代码行数:12,代码来源:qbs_test.go

示例5: assertLegitGraph

func assertLegitGraph(assert *assrt.Assert, g *Graph) {
	assert.NotNil(g)

	gstat, _ := os.Stat(filepath.Join(g.dir))
	assert.True(gstat.IsDir())

	assert.True(g.HasBranch("hroot/init"))

	assert.Equal(
		"",
		g.cmd("ls-tree")("HEAD").Output(),
	)
}
开发者ID:polydawn,项目名称:hroot,代码行数:13,代码来源:graph_integration_test.go

示例6: 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))
}
开发者ID:cgolang,项目名称:qbs,代码行数:19,代码来源:qbs_test.go

示例7: DoTestSelectionSQL

func DoTestSelectionSQL(assert *assrt.Assert, info dialectSyntax) {
	assert.Logf("Dialect %T\n", info.dialect)
	type User struct {
		Id   int64
		Name string
	}
	type Post struct {
		Id       int64
		AuthorId int64 `qbs:"fk:Author"`
		Author   *User
		Content  string
	}
	model := structPtrToModel(new(Post), true, nil)
	criteria := new(Criteria)
	criteria.model = model

	sql, _ := info.dialect.QuerySql(criteria)
	assert.Equal(info.selectionSql, sql)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:19,代码来源:dialect_test.go

示例8: DoTestStringPk

func DoTestStringPk(assert *assrt.Assert, info dialectInfo) {
	type StringPk struct {
		Tag   string `qbs:"pk,size:16"`
		Count int32
	}
	spk := new(StringPk)
	spk.Tag = "health"
	spk.Count = 10
	mg, q := setupDb(assert, info)
	defer mg.Close()
	defer q.Close()
	mg.dropTableIfExists(spk)
	mg.CreateTableIfNotExists(spk)
	affected, _ := q.Save(spk)
	assert.Equal(1, affected)
	spk.Count = 0
	q.Find(spk)
	assert.Equal(10, spk.Count)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:19,代码来源:qbs_test.go

示例9: 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)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:52,代码来源:qbs_test.go

示例10: DoTestQuerySQL

func DoTestQuerySQL(assert *assrt.Assert, info dialectSyntax) {
	assert.Logf("Dialect %T\n", info.dialect)
	type Student struct {
		Name  string
		Grade int
		Score int
	}
	model := structPtrToModel(new(Student), true, nil)
	criteria := new(Criteria)
	criteria.model = model
	condition := NewInCondition("grade", []interface{}{6, 7, 8})
	subCondition := NewCondition("score <= ?", 60).Or("score >= ?", 80)
	condition.AndCondition(subCondition)
	criteria.condition = condition
	criteria.orderBys = []order{order{info.dialect.Quote("name"), false}, order{info.dialect.Quote("grade"), true}}
	criteria.offset = 3
	criteria.limit = 10
	sql, _ := info.dialect.QuerySql(criteria)
	sql = info.dialect.SubstituteMarkers(sql)
	assert.Equal(info.querySql, sql)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:21,代码来源:dialect_test.go

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

示例12: DoTestUpdate

func DoTestUpdate(assert *assrt.Assert, info dialectInfo) {
	mg, q := setupDb(assert, info)
	mg.dropTableIfExists(&basic{})
	mg.CreateTableIfNotExists(&basic{})
	_, err := q.Save(&basic{Name: "a", State: 1})
	_, err = q.Save(&basic{Name: "b", State: 1})
	_, err = q.Save(&basic{Name: "c", State: 0})
	assert.MustNil(err)
	{
		// define a temporary struct in a block to update partial columns of a table
		// as the type is in a block, so it will not conflict with other types with the same name in the same method
		type basic struct {
			Name string
		}
		affected, err := q.Where("state = ?", 1).Update(&basic{Name: "d"})
		assert.MustNil(err)
		assert.Equal(2, affected)

		var datas []*basic
		q.Where("state = ?", 1).FindAll(&datas)
		assert.MustEqual(2, len(datas))
		assert.Equal("d", datas[0].Name)
		assert.Equal("d", datas[1].Name)
	}

	// if choose basic table type to update, all zero value in the struct will be updated too.
	// this may be cause problems, so define a temporary struct to update table is the recommended way.
	affected, err := q.Where("state = ?", 1).Update(&basic{Name: "e"})
	assert.MustNil(err)
	assert.Equal(2, affected)
	var datas []*basic
	q.Where("state = ?", 1).FindAll(&datas)
	assert.MustEqual(0, len(datas))
}
开发者ID:cgolang,项目名称:qbs,代码行数:34,代码来源:qbs_test.go

示例13: DoTestCreateTableSql

func DoTestCreateTableSql(assert *assrt.Assert, info dialectSyntax) {
	assert.Logf("Dialect %T\n", info.dialect)
	type withoutPk struct {
		First  string
		Last   string
		Amount int
	}
	table := &withoutPk{"a", "b", 5}
	model := structPtrToModel(table, true, nil)
	sql := info.dialect.CreateTableSql(model, true)
	assert.Equal(info.createTableWithoutPkIfExistsSql, sql)
	type withPk struct {
		Primary int64 `qbs:"pk"`
		First   string
		Last    string
		Amount  int
	}
	table2 := &withPk{First: "a", Last: "b", Amount: 5}
	model = structPtrToModel(table2, true, nil)
	sql = info.dialect.CreateTableSql(model, false)
	assert.Equal(info.createTableWithPkSql, sql)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:22,代码来源:dialect_test.go

示例14: 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)
}
开发者ID:cgolang,项目名称:qbs,代码行数:36,代码来源:qbs_test.go

示例15: DoTestAddColumSQL

func DoTestAddColumSQL(assert *assrt.Assert, info dialectSyntax) {
	assert.Logf("Dialect %T\n", info.dialect)
	sql := info.dialect.AddColumnSql("a", "c", "", 100)
	assert.Equal(info.addColumnSql, sql)
}
开发者ID:jmcvetta,项目名称:qbs,代码行数:5,代码来源:dialect_test.go


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