Skip to content

Commit

Permalink
tests: Add integration test case for view creation (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku authored and july2993 committed Jul 10, 2019
1 parent 21de84f commit c735661
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/dailytest/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ func RunCase(src *sql.DB, dst *sql.DB, schema string) {
tr.run(caseTblWithGeneratedCol)
tr.execSQLs([]string{"DROP TABLE gen_contacts;"})

tr.run(caseCreateView)
tr.execSQLs([]string{"DROP TABLE base_for_view;"})
tr.execSQLs([]string{"DROP VIEW view_user_sum;"})

// random op on have both pk and uk table
tr.run(func(src *sql.DB) {
start := time.Now()
Expand Down Expand Up @@ -284,6 +288,34 @@ CREATE TABLE gen_contacts (
}
}

func caseCreateView(db *sql.DB) {
mustExec(db, `
CREATE TABLE base_for_view (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
amount INT NOT NULL
);`)

mustExec(db, `
CREATE VIEW view_user_sum (user_id, total)
AS SELECT user_id, SUM(amount) FROM base_for_view GROUP BY user_id;`)

insertSQL := "INSERT INTO base_for_view(user_id, amount) VALUES(?, ?);"
updateSQL := "UPDATE base_for_view SET amount = ? WHERE user_id = ?;"
deleteSQL := "DELETE FROM base_for_view WHERE user_id = ? AND amount = ?;"
for i := 0; i < 42; i++ {
for j := 0; j < 3; j++ {
mustExec(db, insertSQL, i, j*10+i)
if i%2 == 0 && j == 1 {
mustExec(db, updateSQL, 1111, i)
}
}
}
for i := 0; i < 10; i++ {
mustExec(db, deleteSQL, i, 1111)
}
}

// updatePKUK create a table with primary key and unique key
// then do opNum randomly DML
func updatePKUK(db *sql.DB, opNum int) error {
Expand Down

0 comments on commit c735661

Please sign in to comment.