本文整理汇总了Golang中github.com/technotronicoz/testify/assert.EqualError函数的典型用法代码示例。如果您正苦于以下问题:Golang EqualError函数的具体用法?Golang EqualError怎么用?Golang EqualError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EqualError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestScanStructs_WithPreparedStatements
func (me *datasetTest) TestScanStructs_WithPreparedStatements() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT "address", "name" FROM "items" WHERE \(\("address" = \?\) AND \("name" IN \(\?, \?, \?\)\)\)`).
WithArgs("111 Test Addr", "Bob", "Sally", "Billy").
WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1\n211 Test Addr,Test2"))
sqlmock.ExpectQuery(`SELECT "test" FROM "items" WHERE \(\("address" = \?\) AND \("name" IN \(\?, \?, \?\)\)\)`).
WithArgs("111 Test Addr", "Bob", "Sally", "Billy").
WillReturnRows(sqlmock.NewRows([]string{"test"}).FromCSVString("test1\ntest2"))
db := New("mock", mDb)
var items []dsTestActionItem
assert.NoError(t, db.From("items").Prepared(true).Where(Ex{"name": []string{"Bob", "Sally", "Billy"}, "address": "111 Test Addr"}).ScanStructs(&items))
assert.Len(t, items, 2)
assert.Equal(t, items[0].Address, "111 Test Addr")
assert.Equal(t, items[0].Name, "Test1")
assert.Equal(t, items[1].Address, "211 Test Addr")
assert.Equal(t, items[1].Name, "Test2")
items = items[0:0]
assert.EqualError(t, db.From("items").ScanStructs(items), "goqu: Type must be a pointer to a slice when calling ScanStructs")
assert.EqualError(t, db.From("items").ScanStructs(&dsTestActionItem{}), "goqu: Type must be a pointer to a slice when calling ScanStructs")
assert.EqualError(t, db.From("items").
Prepared(true).
Select("test").
Where(Ex{"name": []string{"Bob", "Sally", "Billy"}, "address": "111 Test Addr"}).
ScanStructs(&items), `goqu: Unable to find corresponding field to column "test" returned by query`)
}
示例2: TestScanVal
func (me *crudExecTest) TestScanVal() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT "id" FROM "items"`).
WillReturnError(fmt.Errorf("query error"))
sqlmock.ExpectQuery(`SELECT "id" FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1"))
db := New("db-mock", mDb)
exec := newCrudExec(db, nil, `SELECT "id" FROM "items"`)
var id int64
var ids []int64
found, err := exec.ScanVal(id)
assert.EqualError(t, err, "goqu: Type must be a pointer when calling ScanVal")
assert.False(t, found)
found, err = exec.ScanVal(&ids)
assert.EqualError(t, err, "goqu: Cannot scan into a slice when calling ScanVal")
assert.False(t, found)
found, err = exec.ScanVal(&id)
assert.EqualError(t, err, "query error")
assert.False(t, found)
var ptrId int64
found, err = exec.ScanVal(&ptrId)
assert.NoError(t, err)
assert.Equal(t, ptrId, 1)
}
示例3: TestInsertSqlDifferentTypes
func (me *datasetTest) TestInsertSqlDifferentTypes() {
t := me.T()
ds1 := From("items")
type item struct {
Address string `db:"address"`
Name string `db:"name"`
}
type item2 struct {
Address string `db:"address"`
Name string `db:"name"`
}
_, _, err := ds1.ToInsertSql(
item{Address: "111 Test Addr", Name: "Test1"},
item2{Address: "211 Test Addr", Name: "Test2"},
item{Address: "311 Test Addr", Name: "Test3"},
item2{Address: "411 Test Addr", Name: "Test4"},
)
assert.EqualError(t, err, "goqu: Rows must be all the same type expected goqu.item got goqu.item2")
_, _, err = ds1.ToInsertSql(
item{Address: "111 Test Addr", Name: "Test1"},
map[string]interface{}{"address": "211 Test Addr", "name": "Test2"},
item{Address: "311 Test Addr", Name: "Test3"},
map[string]interface{}{"address": "411 Test Addr", "name": "Test4"},
)
assert.EqualError(t, err, "goqu: Rows must be all the same type expected goqu.item got map[string]interface {}")
}
示例4: TestScanVals
func (me *crudExecTest) TestScanVals() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT "id" FROM "items"`).
WillReturnError(fmt.Errorf("query error"))
sqlmock.ExpectQuery(`SELECT "id" FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1\n2"))
sqlmock.ExpectQuery(`SELECT "id" FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1\n2"))
db := New("db-mock", mDb)
exec := newCrudExec(db, nil, `SELECT "id" FROM "items"`)
var id int64
var ids []int64
assert.EqualError(t, exec.ScanVals(ids), "goqu: Type must be a pointer to a slice when calling ScanVals")
assert.EqualError(t, exec.ScanVals(&id), "goqu: Type must be a pointer to a slice when calling ScanVals")
assert.EqualError(t, exec.ScanVals(&ids), "query error")
assert.NoError(t, exec.ScanVals(&ids))
assert.Equal(t, ids, []int64{1, 2})
var pointers []*int64
assert.NoError(t, exec.ScanVals(&pointers))
assert.Len(t, pointers, 2)
assert.Equal(t, *pointers[0], 1)
assert.Equal(t, *pointers[1], 2)
}
示例5: TestScanStructs
func (me *databaseTest) TestScanStructs() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT \* FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1\n211 Test Addr,Test2"))
sqlmock.ExpectQuery(`SELECT "test" FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"test"}).FromCSVString("test1\ntest2"))
db := New("db-mock", mDb)
var items []testActionItem
assert.NoError(t, db.ScanStructs(&items, `SELECT * FROM "items"`))
assert.Len(t, items, 2)
assert.Equal(t, items[0].Address, "111 Test Addr")
assert.Equal(t, items[0].Name, "Test1")
assert.Equal(t, items[1].Address, "211 Test Addr")
assert.Equal(t, items[1].Name, "Test2")
items = items[0:0]
assert.EqualError(t, db.ScanStructs(items, `SELECT * FROM "items"`), "goqu: Type must be a pointer to a slice when calling ScanStructs")
assert.EqualError(t, db.ScanStructs(&testActionItem{}, `SELECT * FROM "items"`), "goqu: Type must be a pointer to a slice when calling ScanStructs")
assert.EqualError(t, db.ScanStructs(&items, `SELECT "test" FROM "items"`), `goqu: Unable to find corresponding field to column "test" returned by query`)
}
示例6: TestScanStruct
func (me *databaseTest) TestScanStruct() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT \* FROM "items" LIMIT 1`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1"))
sqlmock.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`)
}
示例7: TestScanStruct
func (me *crudExecTest) TestScanStruct() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT \* FROM "items"`).
WillReturnError(fmt.Errorf("query error"))
sqlmock.ExpectQuery(`SELECT \* FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1"))
sqlmock.ExpectQuery(`SELECT \* FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"address", "name", "phone_number", "age"}).FromCSVString("111 Test Addr,Test1,111-111-1111,20"))
sqlmock.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")
}
示例8: TestInsertSqlNoReturning
func (me *datasetTest) TestInsertSqlNoReturning() {
t := me.T()
mDb, _ := sqlmock.New()
ds1 := New("no-return", mDb).From("items")
type item struct {
Address string `db:"address"`
Name string `db:"name"`
}
_, _, err := ds1.Returning("id").ToInsertSql(item{Name: "Test", Address: "111 Test Addr"})
assert.EqualError(t, err, "goqu: Adapter does not support RETURNING clause")
_, _, err = ds1.Returning("id").ToInsertSql(From("test2"))
assert.EqualError(t, err, "goqu: Adapter does not support RETURNING clause")
}
示例9: TestInsertSqlWithMaps
func (me *datasetTest) TestInsertSqlWithMaps() {
t := me.T()
ds1 := From("items")
sql, _, err := ds1.ToInsertSql(map[string]interface{}{"name": "Test", "address": "111 Test Addr"})
assert.NoError(t, err)
assert.Equal(t, sql, `INSERT INTO "items" ("address", "name") VALUES ('111 Test Addr', 'Test')`)
sql, _, err = ds1.ToInsertSql(
map[string]interface{}{"address": "111 Test Addr", "name": "Test1"},
map[string]interface{}{"address": "211 Test Addr", "name": "Test2"},
map[string]interface{}{"address": "311 Test Addr", "name": "Test3"},
map[string]interface{}{"address": "411 Test Addr", "name": "Test4"},
)
assert.NoError(t, err)
assert.Equal(t, sql, `INSERT INTO "items" ("address", "name") VALUES ('111 Test Addr', 'Test1'), ('211 Test Addr', 'Test2'), ('311 Test Addr', 'Test3'), ('411 Test Addr', 'Test4')`)
_, _, err = ds1.ToInsertSql(
map[string]interface{}{"address": "111 Test Addr", "name": "Test1"},
map[string]interface{}{"address": "211 Test Addr"},
map[string]interface{}{"address": "311 Test Addr", "name": "Test3"},
map[string]interface{}{"address": "411 Test Addr", "name": "Test4"},
)
assert.EqualError(t, err, "goqu: Rows with different value length expected 2 got 1")
}
示例10: TestScanVals
func (me *databaseTest) TestScanVals() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT "id" FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1\n2\n3\n4\n5"))
db := New("mock", mDb)
var ids []uint32
assert.NoError(t, db.ScanVals(&ids, `SELECT "id" FROM "items"`))
assert.Len(t, ids, 5)
assert.EqualError(t, db.ScanVals([]uint32{}, `SELECT "id" FROM "items"`), "goqu: Type must be a pointer to a slice when calling ScanVals")
assert.EqualError(t, db.ScanVals(testActionItem{}, `SELECT "id" FROM "items"`), "goqu: Type must be a pointer to a slice when calling ScanVals")
}
示例11: TestInsertSqlWitDifferentKeys
func (me *datasetTest) TestInsertSqlWitDifferentKeys() {
t := me.T()
ds1 := From("items")
_, _, err := ds1.ToInsertSql(
map[string]interface{}{"address": "111 Test Addr", "name": "test"},
map[string]interface{}{"phoneNumber": 10, "address": "111 Test Addr"},
)
assert.EqualError(t, err, `goqu: Rows with different keys expected ["address","name"] got ["address","phoneNumber"]`)
}
示例12: TestWithError
func (me *crudExecTest) TestWithError() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
db := New("db-mock", mDb)
expectedErr := fmt.Errorf("crud exec error")
exec := newCrudExec(db, expectedErr, `SELECT * FROM "items"`)
var items []testCrudActionItem
assert.EqualError(t, exec.ScanStructs(&items), expectedErr.Error())
found, err := exec.ScanStruct(&testCrudActionItem{})
assert.EqualError(t, err, expectedErr.Error())
assert.False(t, found)
var vals []string
assert.EqualError(t, exec.ScanVals(&vals), expectedErr.Error())
var val string
found, err = exec.ScanVal(&val)
assert.EqualError(t, err, expectedErr.Error())
assert.False(t, found)
}
示例13: TestUpdateSqlWithNoSources
func (me *datasetTest) TestUpdateSqlWithNoSources() {
t := me.T()
ds1 := From("items")
type item struct {
Address string `db:"address"`
Name string `db:"name"`
}
_, _, err := ds1.From().ToUpdateSql(item{Name: "Test", Address: "111 Test Addr"})
assert.EqualError(t, err, "goqu: No source found when generating update sql")
}
示例14: TestScanVal
func (me *databaseTest) TestScanVal() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT "id" FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("10"))
db := New("mock", mDb)
var id int64
found, err := db.ScanVal(&id, `SELECT "id" FROM "items"`)
assert.NoError(t, err)
assert.Equal(t, id, 10)
assert.True(t, found)
found, err = db.ScanVal([]int64{}, `SELECT "id" FROM "items"`)
assert.EqualError(t, err, "goqu: Type must be a pointer when calling ScanVal")
found, err = db.ScanVal(10, `SELECT "id" FROM "items"`)
assert.EqualError(t, err, "goqu: Type must be a pointer when calling ScanVal")
}
示例15: TestScanVals_WithPreparedStatment
func (me *datasetTest) TestScanVals_WithPreparedStatment() {
t := me.T()
mDb, err := sqlmock.New()
assert.NoError(t, err)
sqlmock.ExpectQuery(`SELECT "id" FROM "items" WHERE \(\("address" = \?\) AND \("name" IN \(\?, \?, \?\)\)\)`).
WithArgs("111 Test Addr", "Bob", "Sally", "Billy").
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1\n2\n3\n4\n5"))
db := New("mock", mDb)
var ids []uint32
assert.NoError(t, db.From("items").
Prepared(true).
Select("id").
Where(Ex{"name": []string{"Bob", "Sally", "Billy"}, "address": "111 Test Addr"}).
ScanVals(&ids))
assert.Len(t, ids, 5)
assert.EqualError(t, db.From("items").ScanVals([]uint32{}), "goqu: Type must be a pointer to a slice when calling ScanVals")
assert.EqualError(t, db.From("items").ScanVals(dsTestActionItem{}), "goqu: Type must be a pointer to a slice when calling ScanVals")
}