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


Golang assert.True函數代碼示例

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


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

示例1: TestDelete

func (me *mysqlTest) TestDelete() {
	t := me.T()
	ds := me.db.From("entry")
	var e entry
	found, err := ds.Where(goqu.I("int").Eq(9)).Select("id").ScanStruct(&e)
	assert.NoError(t, err)
	assert.True(t, found)
	_, err = ds.Where(goqu.I("id").Eq(e.Id)).Delete().Exec()
	assert.NoError(t, err)

	count, err := ds.Count()
	assert.NoError(t, err)
	assert.Equal(t, count, 9)

	var id uint32
	found, err = ds.Where(goqu.I("id").Eq(e.Id)).ScanVal(&id)
	assert.NoError(t, err)
	assert.False(t, found)

	e = entry{}
	found, err = ds.Where(goqu.I("int").Eq(8)).Select("id").ScanStruct(&e)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.NotEqual(t, e.Id, 0)

	id = 0
	_, err = ds.Where(goqu.I("id").Eq(e.Id)).Returning("id").Delete().ScanVal(&id)
	assert.Equal(t, err.Error(), "goqu: Adapter does not support RETURNING clause")
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:29,代碼來源:mysql_test.go

示例2: TestInsertReturning

func (me *postgresTest) TestInsertReturning() {
	t := me.T()
	ds := me.db.From("entry")
	now := time.Now()
	e := entry{Int: 10, Float: 1.000000, String: "1.000000", Time: now, Bool: true, Bytes: []byte("1.000000")}
	found, err := ds.Returning(goqu.Star()).Insert(e).ScanStruct(&e)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.True(t, e.Id > 0)

	var ids []uint32
	assert.NoError(t, ds.Returning("id").Insert([]entry{
		{Int: 11, Float: 1.100000, String: "1.100000", Time: now, Bool: false, Bytes: []byte("1.100000")},
		{Int: 12, Float: 1.200000, String: "1.200000", Time: now, Bool: true, Bytes: []byte("1.200000")},
		{Int: 13, Float: 1.300000, String: "1.300000", Time: now, Bool: false, Bytes: []byte("1.300000")},
		{Int: 14, Float: 1.400000, String: "1.400000", Time: now, Bool: true, Bytes: []byte("1.400000")},
	}).ScanVals(&ids))
	assert.Len(t, ids, 4)
	for _, id := range ids {
		assert.True(t, id > 0)
	}

	var ints []int64
	assert.NoError(t, ds.Returning("int").Insert(
		entry{Int: 15, Float: 1.500000, String: "1.500000", Time: now, Bool: false, Bytes: []byte("1.500000")},
		entry{Int: 16, Float: 1.600000, String: "1.600000", Time: now, Bool: true, Bytes: []byte("1.600000")},
		entry{Int: 17, Float: 1.700000, String: "1.700000", Time: now, Bool: false, Bytes: []byte("1.700000")},
		entry{Int: 18, Float: 1.800000, String: "1.800000", Time: now, Bool: true, Bytes: []byte("1.800000")},
	).ScanVals(&ints))
	assert.True(t, found)
	assert.Equal(t, ints, []int64{15, 16, 17, 18})
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:32,代碼來源:postgres_test.go

示例3: TestDelete

func (me *postgresTest) TestDelete() {
	t := me.T()
	ds := me.db.From("entry")
	var e entry
	found, err := ds.Where(goqu.I("int").Eq(9)).Select("id").ScanStruct(&e)
	assert.NoError(t, err)
	assert.True(t, found)
	_, err = ds.Where(goqu.I("id").Eq(e.Id)).Delete().Exec()
	assert.NoError(t, err)

	count, err := ds.Count()
	assert.NoError(t, err)
	assert.Equal(t, count, 9)

	var id uint32
	found, err = ds.Where(goqu.I("id").Eq(e.Id)).ScanVal(&id)
	assert.NoError(t, err)
	assert.False(t, found)

	e = entry{}
	found, err = ds.Where(goqu.I("int").Eq(8)).Select("id").ScanStruct(&e)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.NotEqual(t, e.Id, 0)

	id = 0
	_, err = ds.Where(goqu.I("id").Eq(e.Id)).Returning("id").Delete().ScanVal(&id)
	assert.NoError(t, err)
	assert.Equal(t, id, e.Id)
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:30,代碼來源:postgres_test.go

示例4: TestScanStruct

func (me *crudExecTest) TestScanStruct() {
	t := me.T()
	mDb, mock, err := sqlmock.New()
	assert.NoError(t, err)

	mock.ExpectQuery(`SELECT \* FROM "items"`).
		WillReturnError(fmt.Errorf("query error"))

	mock.ExpectQuery(`SELECT \* FROM "items"`).
		WithArgs().
		WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1"))

	mock.ExpectQuery(`SELECT \* FROM "items"`).
		WithArgs().
		WillReturnRows(sqlmock.NewRows([]string{"address", "name", "phone_number", "age"}).FromCSVString("111 Test Addr,Test1,111-111-1111,20"))

	mock.ExpectQuery(`SELECT \* FROM "items"`).
		WithArgs().
		WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1"))

	db := New("db-mock", mDb)
	exec := newCrudExec(db, nil, `SELECT * FROM "items"`)

	var slicePtr []testCrudActionItem
	var item testCrudActionItem
	found, err := exec.ScanStruct(item)
	assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct")
	assert.False(t, found)
	found, err = exec.ScanStruct(&slicePtr)
	assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct")
	assert.False(t, found)
	found, err = exec.ScanStruct(&item)
	assert.EqualError(t, err, "query error")
	assert.False(t, found)

	found, err = exec.ScanStruct(&item)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.Equal(t, item.Address, "111 Test Addr")
	assert.Equal(t, item.Name, "Test1")

	var composed testComposedCrudActionItem
	found, err = exec.ScanStruct(&composed)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.Equal(t, composed.Address, "111 Test Addr")
	assert.Equal(t, composed.Name, "Test1")
	assert.Equal(t, composed.PhoneNumber, "111-111-1111")
	assert.Equal(t, composed.Age, 20)

	var noTag testCrudActionNoTagsItem
	found, err = exec.ScanStruct(&noTag)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.Equal(t, noTag.Address, "111 Test Addr")
	assert.Equal(t, noTag.Name, "Test1")
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:57,代碼來源:crud_exec_test.go

示例5: TestPrepared

func (me *datasetTest) TestPrepared() {
	t := me.T()
	ds := From("test")
	preparedDs := ds.Prepared(true)
	assert.True(t, preparedDs.isPrepared)
	assert.False(t, ds.isPrepared)

	//should apply the prepared to any datasets created from the root
	assert.True(t, preparedDs.Where(Ex{"a": 1}).isPrepared)
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:10,代碼來源:dataset_test.go

示例6: Test_Mock_AssertNumberOfCalls

func Test_Mock_AssertNumberOfCalls(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.On("Test_Mock_AssertNumberOfCalls", 1, 2, 3).Return(5, 6, 7)

	mockedService.Called(1, 2, 3)
	assert.True(t, mockedService.AssertNumberOfCalls(t, "Test_Mock_AssertNumberOfCalls", 1))

	mockedService.Called(1, 2, 3)
	assert.True(t, mockedService.AssertNumberOfCalls(t, "Test_Mock_AssertNumberOfCalls", 2))

}
開發者ID:C2FO,項目名稱:testify,代碼行數:13,代碼來源:mock_test.go

示例7: AssertCalled

// AssertCalled asserts that the method was called.
func (m *Mock) AssertCalled(t TestingT, methodName string, arguments ...interface{}) bool {
	if !assert.True(t, m.methodWasCalled(methodName, arguments), fmt.Sprintf("The \"%s\" method should have been called with %d argument(s), but was not.", methodName, len(arguments))) {
		t.Logf("%v", m.expectedCalls())
		return false
	}
	return true
}
開發者ID:C2FO,項目名稱:testify,代碼行數:8,代碼來源:mock.go

示例8: TestScanStruct_WithPreparedStatements

func (me *datasetTest) TestScanStruct_WithPreparedStatements() {
	t := me.T()
	mDb, mock, err := sqlmock.New()
	assert.NoError(t, err)
	mock.ExpectQuery(`SELECT "address", "name" FROM "items" WHERE \(\("address" = \?\) AND \("name" IN \(\?, \?, \?\)\)\) LIMIT \?`).
		WithArgs("111 Test Addr", "Bob", "Sally", "Billy", 1).
		WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1"))

	mock.ExpectQuery(`SELECT "test" FROM "items" WHERE \(\("address" = \?\) AND \("name" IN \(\?, \?, \?\)\)\) LIMIT \?`).
		WithArgs("111 Test Addr", "Bob", "Sally", "Billy", 1).
		WillReturnRows(sqlmock.NewRows([]string{"test"}).FromCSVString("test1\ntest2"))

	db := New("mock", mDb)
	var item dsTestActionItem
	found, err := db.From("items").Prepared(true).Where(Ex{"name": []string{"Bob", "Sally", "Billy"}, "address": "111 Test Addr"}).ScanStruct(&item)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.Equal(t, item.Address, "111 Test Addr")
	assert.Equal(t, item.Name, "Test1")

	_, err = db.From("items").ScanStruct(item)
	assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct")
	_, err = db.From("items").ScanStruct([]dsTestActionItem{})
	assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct")
	_, err = db.From("items").
		Prepared(true).
		Select("test").
		Where(Ex{"name": []string{"Bob", "Sally", "Billy"}, "address": "111 Test Addr"}).
		ScanStruct(&item)
	assert.EqualError(t, err, `goqu: Unable to find corresponding field to column "test" returned by query`)
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:31,代碼來源:dataset_actions_test.go

示例9: TestScanStruct

func (me *databaseTest) TestScanStruct() {
	t := me.T()
	mDb, mock, err := sqlmock.New()
	assert.NoError(t, err)
	mock.ExpectQuery(`SELECT \* FROM "items" LIMIT 1`).
		WithArgs().
		WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1"))

	mock.ExpectQuery(`SELECT "test" FROM "items" LIMIT 1`).
		WithArgs().
		WillReturnRows(sqlmock.NewRows([]string{"test"}).FromCSVString("test1\ntest2"))

	db := New("mock", mDb)
	var item testActionItem
	found, err := db.ScanStruct(&item, `SELECT * FROM "items" LIMIT 1`)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.Equal(t, item.Address, "111 Test Addr")
	assert.Equal(t, item.Name, "Test1")

	_, err = db.ScanStruct(item, `SELECT * FROM "items" LIMIT 1`)
	assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct")
	_, err = db.ScanStruct([]testActionItem{}, `SELECT * FROM "items" LIMIT 1`)
	assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct")
	_, err = db.ScanStruct(&item, `SELECT "test" FROM "items" LIMIT 1`)
	assert.EqualError(t, err, `goqu: Unable to find corresponding field to column "test" returned by query`)
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:27,代碼來源:database_test.go

示例10: Test_Arguments_Assert

func Test_Arguments_Assert(t *testing.T) {

	var args Arguments = []interface{}{"string", 123, true}

	assert.True(t, args.Assert(t, "string", 123, true))

}
開發者ID:C2FO,項目名稱:testify,代碼行數:7,代碼來源:mock_test.go

示例11: Test_Mock_AssertCalled_WithArguments_With_Repeatability

func Test_Mock_AssertCalled_WithArguments_With_Repeatability(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.On("Test_Mock_AssertCalled_WithArguments_With_Repeatability", 1, 2, 3).Return(5, 6, 7).Once()
	mockedService.On("Test_Mock_AssertCalled_WithArguments_With_Repeatability", 2, 3, 4).Return(5, 6, 7).Once()

	mockedService.Called(1, 2, 3)
	mockedService.Called(2, 3, 4)

	tt := new(testing.T)
	assert.True(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 1, 2, 3))
	assert.True(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 2, 3, 4))
	assert.False(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 3, 4, 5))

}
開發者ID:C2FO,項目名稱:testify,代碼行數:16,代碼來源:mock_test.go

示例12: TestRegisterAdapter

func (me *adapterTest) TestRegisterAdapter() {
	t := me.T()
	RegisterAdapter("test", func(ds *Dataset) Adapter {
		return NewDefaultAdapter(ds)
	})
	assert.True(t, HasAdapter("test"))
	removeAdapter("test")
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:8,代碼來源:adapters_test.go

示例13: Test_Arguments_Is

func Test_Arguments_Is(t *testing.T) {

	var args Arguments = []interface{}{"string", 123, true}

	assert.True(t, args.Is("string", 123, true))
	assert.False(t, args.Is("wrong", 456, false))

}
開發者ID:C2FO,項目名稱:testify,代碼行數:8,代碼來源:mock_test.go

示例14: Test_Mock_AssertCalled_WithAnythingOfTypeArgument

func Test_Mock_AssertCalled_WithAnythingOfTypeArgument(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.On("Test_Mock_AssertCalled_WithAnythingOfTypeArgument", Anything, Anything, Anything).Return()

	mockedService.Called(1, "two", []uint8("three"))

	assert.True(t, mockedService.AssertCalled(t, "Test_Mock_AssertCalled_WithAnythingOfTypeArgument", AnythingOfType("int"), AnythingOfType("string"), AnythingOfType("[]uint8")))

}
開發者ID:C2FO,項目名稱:testify,代碼行數:11,代碼來源:mock_test.go

示例15: TestUpdate

func (me *postgresTest) TestUpdate() {
	t := me.T()
	ds := me.db.From("entry")
	var e entry
	found, err := ds.Where(goqu.I("int").Eq(9)).Select("id").ScanStruct(&e)
	assert.NoError(t, err)
	assert.True(t, found)
	e.Int = 11
	_, err = ds.Where(goqu.I("id").Eq(e.Id)).Update(e).Exec()
	assert.NoError(t, err)

	count, err := ds.Where(goqu.I("int").Eq(11)).Count()
	assert.NoError(t, err)
	assert.Equal(t, count, 1)

	var id uint32
	found, err = ds.Where(goqu.I("int").Eq(11)).Returning("id").Update(map[string]interface{}{"int": 9}).ScanVal(&id)
	assert.NoError(t, err)
	assert.True(t, found)
	assert.Equal(t, id, e.Id)
}
開發者ID:ruzz311,項目名稱:goqu,代碼行數:21,代碼來源:postgres_test.go


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