-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes expectations no arg exp but act args passed
- Loading branch information
Showing
4 changed files
with
16 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -959,7 +959,7 @@ func TestPrepareExec(t *testing.T) { | |
mock.ExpectBegin() | ||
ep := mock.ExpectPrepare("INSERT INTO ORDERS\\(ID, STATUS\\) VALUES \\(\\?, \\?\\)") | ||
for i := 0; i < 3; i++ { | ||
ep.ExpectExec().WillReturnResult(NewResult(1, 1)) | ||
ep.ExpectExec().WithArgs(i, "Hello"+strconv.Itoa(i)).WillReturnResult(NewResult(1, 1)) | ||
} | ||
mock.ExpectCommit() | ||
tx, _ := db.Begin() | ||
|
@@ -1073,7 +1073,7 @@ func TestPreparedStatementCloseExpectation(t *testing.T) { | |
defer db.Close() | ||
|
||
ep := mock.ExpectPrepare("INSERT INTO ORDERS").WillBeClosed() | ||
ep.ExpectExec().WillReturnResult(NewResult(1, 1)) | ||
ep.ExpectExec().WithArgs(1, "Hello").WillReturnResult(NewResult(1, 1)) | ||
|
||
stmt, err := db.Prepare("INSERT INTO ORDERS(ID, STATUS) VALUES (?, ?)") | ||
if err != nil { | ||
|
@@ -1102,9 +1102,9 @@ func TestExecExpectationErrorDelay(t *testing.T) { | |
defer db.Close() | ||
|
||
// test that return of error is delayed | ||
var delay time.Duration | ||
delay = 100 * time.Millisecond | ||
var delay time.Duration = 100 * time.Millisecond | ||
mock.ExpectExec("^INSERT INTO articles"). | ||
WithArgs("hello"). | ||
WillReturnError(errors.New("slow fail")). | ||
WillDelayFor(delay) | ||
|
||
|
@@ -1230,10 +1230,10 @@ func Test_sqlmock_Prepare_and_Exec(t *testing.T) { | |
|
||
mock.ExpectPrepare("SELECT (.+) FROM users WHERE (.+)") | ||
expected := NewResult(1, 1) | ||
mock.ExpectExec("SELECT (.+) FROM users WHERE (.+)"). | ||
mock.ExpectExec("SELECT (.+) FROM users WHERE (.+)").WithArgs("test"). | ||
WillReturnResult(expected) | ||
expectedRows := mock.NewRows([]string{"id", "name", "email"}).AddRow(1, "test", "[email protected]") | ||
mock.ExpectQuery("SELECT (.+) FROM users WHERE (.+)").WillReturnRows(expectedRows) | ||
mock.ExpectQuery("SELECT (.+) FROM users WHERE (.+)").WithArgs("test").WillReturnRows(expectedRows) | ||
|
||
got, err := mock.(*sqlmock).Prepare(query) | ||
if err != nil { | ||
|
@@ -1326,7 +1326,7 @@ func Test_sqlmock_Query(t *testing.T) { | |
} | ||
defer db.Close() | ||
expectedRows := mock.NewRows([]string{"id", "name", "email"}).AddRow(1, "test", "[email protected]") | ||
mock.ExpectQuery("SELECT (.+) FROM users WHERE (.+)").WillReturnRows(expectedRows) | ||
mock.ExpectQuery("SELECT (.+) FROM users WHERE (.+)").WithArgs("test").WillReturnRows(expectedRows) | ||
query := "SELECT name, email FROM users WHERE name = ?" | ||
rows, err := mock.(*sqlmock).Query(query, []driver.Value{"test"}) | ||
if err != nil { | ||
|
37b1bab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why must need use args
37b1bab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chichu1439 please have a look at #329. Which will make this strict validation optional.