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


Golang Assert.NotNil方法代碼示例

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


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

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

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

示例3: DoTestFind

func DoTestFind(assert *assrt.Assert, info dialectInfo) {
	mg, q := setupDb(assert, info)
	defer mg.Close()
	defer q.Close()
	now := time.Now()

	type types struct {
		Id    int64
		Str   string
		Intgr int64
		Flt   float64
		Bytes []byte
		Time  time.Time
	}
	modelData := &types{
		Str:   "string!",
		Intgr: -1,
		Flt:   3.8,
		Bytes: []byte("bytes!"),
		Time:  now,
	}

	mg.dropTableIfExists(modelData)
	mg.CreateTableIfNotExists(modelData)

	out := new(types)
	condition := NewCondition("str = ?", "string!").And("intgr = ?", -1)
	err := q.Condition(condition).Find(out)
	assert.Equal(sql.ErrNoRows, err)

	affected, err := q.Save(modelData)
	assert.Nil(err)
	assert.Equal(1, affected)
	out.Id = modelData.Id
	err = q.Condition(condition).Find(out)
	assert.Nil(err)
	assert.Equal(1, out.Id)
	assert.Equal("string!", out.Str)
	assert.Equal(-1, out.Intgr)
	assert.Equal(3.8, out.Flt)
	assert.Equal([]byte("bytes!"), out.Bytes)
	diff := now.Sub(out.Time)
	assert.True(diff < time.Second && diff > -time.Second)

	modelData.Id = 5
	modelData.Str = "New row"
	_, err = q.Save(modelData)
	assert.Nil(err)

	out = new(types)
	condition = NewCondition("str = ?", "New row").And("flt = ?", 3.8)
	err = q.Condition(condition).Find(out)
	assert.Nil(err)
	assert.Equal(5, out.Id)

	out = new(types)
	out.Id = 100
	err = q.Find(out)
	assert.NotNil(err)

	allOut := []*types{}
	err = q.WhereEqual("intgr", -1).FindAll(&allOut)
	assert.Nil(err)
	assert.Equal(2, len(allOut))
}
開發者ID:jmcvetta,項目名稱:qbs,代碼行數:65,代碼來源:qbs_test.go


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