本文整理匯總了Golang中github.com/c2fo/testify/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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")
}
示例2: 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)
}
示例3: TestScanVals
func (me *crudExecTest) TestScanVals() {
t := me.T()
mDb, mock, err := sqlmock.New()
assert.NoError(t, err)
mock.ExpectQuery(`SELECT "id" FROM "items"`).
WillReturnError(fmt.Errorf("query error"))
mock.ExpectQuery(`SELECT "id" FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1\n2"))
mock.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)
}
示例4: 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`)
}
示例5: TestPreparedWhere
func (me *datasetTest) TestPreparedWhere() {
t := me.T()
ds1 := From("test")
b := ds1.Where(Ex{
"a": true,
"b": Op{"neq": true},
"c": false,
"d": Op{"neq": false},
})
sql, args, err := b.Prepared(true).ToSql()
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{})
assert.Equal(t, sql, `SELECT * FROM "test" WHERE (("a" IS TRUE) AND ("b" IS NOT TRUE) AND ("c" IS FALSE) AND ("d" IS NOT FALSE))`)
b = ds1.Where(Ex{
"a": "a",
"b": Op{"neq": "b"},
"c": Op{"gt": "c"},
"d": Op{"gte": "d"},
"e": Op{"lt": "e"},
"f": Op{"lte": "f"},
})
sql, args, err = b.Prepared(true).ToSql()
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{"a", "b", "c", "d", "e", "f"})
assert.Equal(t, sql, `SELECT * FROM "test" WHERE (("a" = ?) AND ("b" != ?) AND ("c" > ?) AND ("d" >= ?) AND ("e" < ?) AND ("f" <= ?))`)
}
示例6: TestPreparedInsertSqlWithValuerNull
func (me *datasetTest) TestPreparedInsertSqlWithValuerNull() {
t := me.T()
ds1 := From("items")
type item struct {
Address string `db:"address"`
Name string `db:"name"`
Valuer sql.NullInt64 `db:"valuer"`
}
sqlString, args, err := ds1.Prepared(true).ToInsertSql(item{Name: "Test", Address: "111 Test Addr"})
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{
"111 Test Addr", "Test", nil,
})
assert.Equal(t, sqlString, `INSERT INTO "items" ("address", "name", "valuer") VALUES (?, ?, ?)`)
sqlString, args, err = ds1.Prepared(true).ToInsertSql(
item{Address: "111 Test Addr", Name: "Test1"},
item{Address: "211 Test Addr", Name: "Test2"},
item{Address: "311 Test Addr", Name: "Test3"},
item{Address: "411 Test Addr", Name: "Test4"},
)
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{
"111 Test Addr", "Test1", nil,
"211 Test Addr", "Test2", nil,
"311 Test Addr", "Test3", nil,
"411 Test Addr", "Test4", nil,
})
assert.Equal(t, sqlString, `INSERT INTO "items" ("address", "name", "valuer") VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?), (?, ?, ?)`)
}
示例7: TestInsertWithGoquPkTagSql
func (me *datasetTest) TestInsertWithGoquPkTagSql() {
t := me.T()
ds1 := From("items")
type item struct {
Id uint32 `db:"id" goqu:"pk,skipinsert"`
Address string `db:"address"`
Name string `db:"name"`
}
sql, _, err := ds1.ToInsertSql(item{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{}{"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(
item{Name: "Test1", Address: "111 Test Addr"},
item{Name: "Test2", Address: "211 Test Addr"},
item{Name: "Test3", Address: "311 Test Addr"},
item{Name: "Test4", Address: "411 Test Addr"},
)
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')`)
}
示例8: TestInsertSqlWithEmbeddedStructPtr
func (me *datasetTest) TestInsertSqlWithEmbeddedStructPtr() {
t := me.T()
ds1 := From("items")
type Phone struct {
Primary string `db:"primary_phone"`
Home string `db:"home_phone"`
}
type item struct {
*Phone
Address string `db:"address"`
Name string `db:"name"`
Valuer sql.NullInt64 `db:"valuer"`
}
sql, _, err := ds1.ToInsertSql(item{Name: "Test", Address: "111 Test Addr", Valuer: sql.NullInt64{Int64: 10, Valid: true}, Phone: &Phone{Home: "123123", Primary: "456456"}})
assert.NoError(t, err)
assert.Equal(t, sql, `INSERT INTO "items" ("primary_phone", "home_phone", "address", "name", "valuer") VALUES ('456456', '123123', '111 Test Addr', 'Test', 10)`)
sql, _, err = ds1.ToInsertSql(
item{Address: "111 Test Addr", Name: "Test1", Phone: &Phone{Home: "123123", Primary: "456456"}},
item{Address: "211 Test Addr", Name: "Test2", Phone: &Phone{Home: "123123", Primary: "456456"}},
item{Address: "311 Test Addr", Name: "Test3", Phone: &Phone{Home: "123123", Primary: "456456"}},
item{Address: "411 Test Addr", Name: "Test4", Phone: &Phone{Home: "123123", Primary: "456456"}},
)
assert.NoError(t, err)
assert.Equal(t, sql, `INSERT INTO "items" ("primary_phone", "home_phone", "address", "name", "valuer") VALUES ('456456', '123123', '111 Test Addr', 'Test1', NULL), ('456456', '123123', '211 Test Addr', 'Test2', NULL), ('456456', '123123', '311 Test Addr', 'Test3', NULL), ('456456', '123123', '411 Test Addr', 'Test4', NULL)`)
}
示例9: TestPreparedInsertSqlWithEmbeddedStructPtr
func (me *datasetTest) TestPreparedInsertSqlWithEmbeddedStructPtr() {
t := me.T()
ds1 := From("items")
type Phone struct {
Primary string `db:"primary_phone"`
Home string `db:"home_phone"`
}
type item struct {
*Phone
Address string `db:"address"`
Name string `db:"name"`
}
sql, args, err := ds1.Prepared(true).ToInsertSql(item{Name: "Test", Address: "111 Test Addr", Phone: &Phone{Home: "123123", Primary: "456456"}})
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{"456456", "123123", "111 Test Addr", "Test"})
assert.Equal(t, sql, `INSERT INTO "items" ("primary_phone", "home_phone", "address", "name") VALUES (?, ?, ?, ?)`)
sql, args, err = ds1.Prepared(true).ToInsertSql(
item{Address: "111 Test Addr", Name: "Test1", Phone: &Phone{Home: "123123", Primary: "456456"}},
item{Address: "211 Test Addr", Name: "Test2", Phone: &Phone{Home: "123123", Primary: "456456"}},
item{Address: "311 Test Addr", Name: "Test3", Phone: &Phone{Home: "123123", Primary: "456456"}},
item{Address: "411 Test Addr", Name: "Test4", Phone: &Phone{Home: "123123", Primary: "456456"}},
)
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{
"456456", "123123", "111 Test Addr", "Test1",
"456456", "123123", "211 Test Addr", "Test2",
"456456", "123123", "311 Test Addr", "Test3",
"456456", "123123", "411 Test Addr", "Test4",
})
assert.Equal(t, sql, `INSERT INTO "items" ("primary_phone", "home_phone", "address", "name") VALUES (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?)`)
}
示例10: TestPreparedUpdateSqlWithEmbeddedStructPtr
func (me *datasetTest) TestPreparedUpdateSqlWithEmbeddedStructPtr() {
t := me.T()
ds1 := From("items")
type phone struct {
Primary string `db:"primary_phone"`
Home string `db:"home_phone"`
Created time.Time `db:"phone_created"`
}
type item struct {
*phone
Address string `db:"address" goqu:"skipupdate"`
Name string `db:"name"`
Created time.Time `db:"created"`
}
created, _ := time.Parse("2006-01-02", "2015-01-01")
sql, args, err := ds1.Prepared(true).ToUpdateSql(item{Name: "Test", Address: "111 Test Addr", Created: created, phone: &phone{
Home: "123123",
Primary: "456456",
Created: created,
}})
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{"456456", "123123", created, "Test", created})
assert.Equal(t, sql, `UPDATE "items" SET "primary_phone"=?,"home_phone"=?,"phone_created"=?,"name"=?,"created"=?`)
}
示例11: TestUpdateSqlWithEmbeddedStruct
func (me *datasetTest) TestUpdateSqlWithEmbeddedStruct() {
t := me.T()
ds1 := From("items")
type phone struct {
Primary string `db:"primary_phone"`
Home string `db:"home_phone"`
Created time.Time `db:"phone_created"`
}
type item struct {
phone
Address string `db:"address" goqu:"skipupdate"`
Name string `db:"name"`
Created time.Time `db:"created"`
NilPointer interface{} `db:"nil_pointer"`
}
created, _ := time.Parse("2006-01-02", "2015-01-01")
sql, args, err := ds1.ToUpdateSql(item{Name: "Test", Address: "111 Test Addr", Created: created, phone: phone{
Home: "123123",
Primary: "456456",
Created: created,
}})
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{})
assert.Equal(t, sql, `UPDATE "items" SET "primary_phone"='456456',"home_phone"='123123',"phone_created"='2015-01-01T00:00:00Z',"name"='Test',"created"='2015-01-01T00:00:00Z',"nil_pointer"=NULL`)
}
示例12: TestInsertSqlWithEmbeddedStruct
func (me *datasetTest) TestInsertSqlWithEmbeddedStruct() {
t := me.T()
ds1 := From("items")
type Phone struct {
Primary string `db:"primary_phone"`
Home string `db:"home_phone"`
}
type item struct {
Phone
Address string `db:"address"`
Name string `db:"name"`
}
sql, _, err := ds1.ToInsertSql(item{Name: "Test", Address: "111 Test Addr", Phone: Phone{Home: "123123", Primary: "456456"}})
assert.NoError(t, err)
assert.Equal(t, sql, `INSERT INTO "items" ("primary_phone", "home_phone", "address", "name") VALUES ('456456', '123123', '111 Test Addr', 'Test')`)
sql, _, err = ds1.ToInsertSql(
item{Address: "111 Test Addr", Name: "Test1", Phone: Phone{Home: "123123", Primary: "456456"}},
item{Address: "211 Test Addr", Name: "Test2", Phone: Phone{Home: "123123", Primary: "456456"}},
item{Address: "311 Test Addr", Name: "Test3", Phone: Phone{Home: "123123", Primary: "456456"}},
item{Address: "411 Test Addr", Name: "Test4", Phone: Phone{Home: "123123", Primary: "456456"}},
)
assert.NoError(t, err)
assert.Equal(t, sql, `INSERT INTO "items" ("primary_phone", "home_phone", "address", "name") VALUES ('456456', '123123', '111 Test Addr', 'Test1'), ('456456', '123123', '211 Test Addr', 'Test2'), ('456456', '123123', '311 Test Addr', 'Test3'), ('456456', '123123', '411 Test Addr', 'Test4')`)
}
示例13: 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")
}
示例14: TestScanStructs
func (me *databaseTest) TestScanStructs() {
t := me.T()
mDb, mock, err := sqlmock.New()
assert.NoError(t, err)
mock.ExpectQuery(`SELECT \* FROM "items"`).
WithArgs().
WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1\n211 Test Addr,Test2"))
mock.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`)
}
示例15: TestJoin
func (me *datasetTest) TestJoin() {
t := me.T()
ds1 := From("items")
sql, _, err := ds1.Join(I("players").As("p"), On(Ex{"p.id": I("items.playerId")})).ToSql()
assert.NoError(t, err)
assert.Equal(t, sql, `SELECT * FROM "items" INNER JOIN "players" AS "p" ON ("p"."id" = "items"."playerId")`)
sql, _, err = ds1.Join(ds1.From("players").As("p"), On(Ex{"p.id": I("items.playerId")})).ToSql()
assert.NoError(t, err)
assert.Equal(t, sql, `SELECT * FROM "items" INNER JOIN (SELECT * FROM "players") AS "p" ON ("p"."id" = "items"."playerId")`)
sql, _, err = ds1.Join(I("v1").Table("test"), On(Ex{"v1.test.id": I("items.playerId")})).ToSql()
assert.NoError(t, err)
assert.Equal(t, sql, `SELECT * FROM "items" INNER JOIN "v1"."test" ON ("v1"."test"."id" = "items"."playerId")`)
sql, _, err = ds1.Join(I("test"), Using(I("name"), I("common_id"))).ToSql()
assert.NoError(t, err)
assert.Equal(t, sql, `SELECT * FROM "items" INNER JOIN "test" USING ("name", "common_id")`)
sql, _, err = ds1.Join(I("test"), Using("name", "common_id")).ToSql()
assert.NoError(t, err)
assert.Equal(t, sql, `SELECT * FROM "items" INNER JOIN "test" USING ("name", "common_id")`)
}