當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assrt.Assert類代碼示例

本文整理匯總了Golang中github.com/coocood/assrt.Assert的典型用法代碼示例。如果您正苦於以下問題:Golang Assert類的具體用法?Golang Assert怎麽用?Golang Assert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Assert類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

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

示例2: setupDb

func setupDb(assert *assrt.Assert, info dialectInfo) (*Migration, *Qbs) {
	db1, err := info.openDbFunc()
	assert.MustNil(err)
	mg := NewMigration(db1, dbName, info.dialect)
	db2, err := info.openDbFunc()
	assert.MustNil(err)
	q := New(db2, info.dialect)
	q.Log = true
	return mg, q
}
開發者ID:cgolang,項目名稱:qbs,代碼行數:10,代碼來源:qbs_test.go

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

示例4: DoTestBoolType

func DoTestBoolType(assert *assrt.Assert, info dialectInfo) {
	type BoolType struct {
		Id     int64
		Active bool
	}
	bt := new(BoolType)
	mg, q := setupDb(assert, info)
	defer mg.Close()
	defer q.Close()
	mg.dropTableIfExists(bt)
	mg.CreateTableIfNotExists(bt)
	bt.Active = true
	q.Save(bt)
	bt.Active = false
	q.WhereEqual("active", true).Find(bt)
	assert.True(bt.Active)
}
開發者ID:jmcvetta,項目名稱:qbs,代碼行數:17,代碼來源:qbs_test.go

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

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

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

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

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

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

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

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

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

示例14: DoTestDropTableSQL

func DoTestDropTableSQL(assert *assrt.Assert, info dialectSyntax) {
	assert.Logf("Dialect %T\n", info.dialect)
	sql := info.dialect.DropTableSql("drop_table")
	assert.Equal(info.dropTableIfExistsSql, sql)
}
開發者ID:jmcvetta,項目名稱:qbs,代碼行數:5,代碼來源:dialect_test.go

示例15: DoTestSaveAndDelete

func DoTestSaveAndDelete(assert *assrt.Assert, info dialectInfo) {
	x := time.Now()
	assert.MustZero(x.Sub(x.UTC()))
	now := time.Now()
	mg, q := setupDb(assert, info)
	type saveModel struct {
		Id      Id
		A       string
		B       int
		Updated time.Time
		Created time.Time
	}
	model1 := saveModel{
		A: "banana",
		B: 5,
	}
	model2 := saveModel{
		A: "orange",
		B: 4,
	}

	mg.dropTableIfExists(&model1)
	mg.CreateTableIfNotExists(&model1)
	affected, err := q.Save(&model1)
	assert.MustNil(err)
	assert.Equal(1, affected)
	assert.True(model1.Created.Sub(now) > 0)
	assert.True(model1.Updated.Sub(now) > 0)

	// make sure created/updated values match the db
	var model1r []*saveModel
	err = q.Where("id = ?", model1.Id).FindAll(&model1r)
	assert.MustNil(err)
	assert.MustOneLen(model1r)
	assert.Equal(model1.Created.Unix(), model1r[0].Created.Unix())
	assert.Equal(model1.Updated.Unix(), model1r[0].Updated.Unix())

	oldCreate := model1.Created
	oldUpdate := model1.Updated
	model1.A = "grape"
	model1.B = 9

	time.Sleep(time.Second * 1) // sleep for 1 sec

	affected, err = q.Save(&model1)
	assert.MustNil(err)
	assert.MustEqual(1, affected)
	assert.True(model1.Created.Equal(oldCreate))
	assert.True(model1.Updated.Sub(oldUpdate) > 0)

	// make sure created/updated values match the db
	var model1r2 []*saveModel
	err = q.Where("id = ?", model1.Id).FindAll(&model1r2)
	assert.MustNil(err)
	assert.MustOneLen(model1r2)
	assert.True(model1r2[0].Updated.Sub(model1r2[0].Created) >= 1)
	assert.Equal(model1.Created.Unix(), model1r2[0].Created.Unix())
	assert.Equal(model1.Updated.Unix(), model1r2[0].Updated.Unix())

	affected, err = q.Save(&model2)
	assert.MustNil(err)
	assert.Equal(1, affected)

	affected, err = q.Delete(&model2)
	assert.MustNil(err)
	assert.Equal(1, affected)
}
開發者ID:cgolang,項目名稱:qbs,代碼行數:67,代碼來源:qbs_test.go


注:本文中的github.com/coocood/assrt.Assert類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。