Skip to content

Commit

Permalink
[shanyujie]rename unit test function name, use standalone sql for Tes…
Browse files Browse the repository at this point in the history
…t_OrderBy_Statement_Generated
  • Loading branch information
shanyujie committed Sep 25, 2024
1 parent 34231b3 commit fc90cdd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions contrib/drivers/mysql/mysql_z_unit_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4788,21 +4788,21 @@ func Test_Model_FixGdbJoin(t *testing.T) {
})
}

func TestOrderByStatementGenerated(t *testing.T) {
func Test_OrderBy_Statement_Generated(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
array := gstr.SplitAndTrim(gtest.DataContent(`table_with_prefix.sql`), ";")
array := gstr.SplitAndTrim(gtest.DataContent(`fix_gdb_order_by.sql`), ";")
for _, v := range array {
if _, err := db.Exec(ctx, v); err != nil {
gtest.Error(err)
}
}
defer dropTable(`instance`)
defer dropTable(`employee`)
sqlArray, _ := gdb.CatchSQL(ctx, func(ctx context.Context) error {
g.DB("default").Ctx(ctx).Model("instance").Order("f_id asc", "name desc").All()
g.DB("default").Ctx(ctx).Model("employee").Order("name asc", "age desc").All()
return nil
})
rawSql := strings.ReplaceAll(sqlArray[len(sqlArray)-1], " ", "")
expectSql := strings.ReplaceAll("SELECT * FROM `instance` ORDER BY `f_id` asc, `name` desc", " ", "")
expectSql := strings.ReplaceAll("SELECT * FROM `employee` ORDER BY `name` asc, `age` desc", " ", "")
t.Assert(rawSql, expectSql)
})
}
9 changes: 9 additions & 0 deletions contrib/drivers/mysql/testdata/fix_gdb_order_by.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `employee`
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age INT NOT NULL
);

INSERT INTO employee(name, age) VALUES ('John', 30);
INSERT INTO employee(name, age) VALUES ('Mary', 28);

0 comments on commit fc90cdd

Please sign in to comment.