1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2025-01-07 23:01:44 +02:00

Merge pull request #56 from gliptak/expectations1

Aditional tests for rollback and commit
This commit is contained in:
Gediminas Morkevicius 2016-11-26 12:17:07 +02:00 committed by GitHub
commit 86364abb39

View File

@ -808,4 +808,62 @@ func TestRollbackThrow(t *testing.T) {
fmt.Printf("unmet expectation error: %s", err)
}
// Output:
}
func TestUnexpectedCommit(t *testing.T) {
// Open new mock database
db, mock, err := New()
if err != nil {
fmt.Println("error creating mock database")
return
}
mock.ExpectBegin()
tx, _ := db.Begin()
if err := tx.Commit(); err == nil {
t.Error("an error was expected when calling commit, but got none")
}
}
func TestUnexpectedCommitOrder(t *testing.T) {
// Open new mock database
db, mock, err := New()
if err != nil {
fmt.Println("error creating mock database")
return
}
mock.ExpectBegin()
mock.ExpectRollback()
tx, _ := db.Begin()
if err := tx.Commit(); err == nil {
t.Error("an error was expected when calling commit, but got none")
}
}
func TestUnexpectedRollback(t *testing.T) {
// Open new mock database
db, mock, err := New()
if err != nil {
fmt.Println("error creating mock database")
return
}
mock.ExpectBegin()
tx, _ := db.Begin()
if err := tx.Rollback(); err == nil {
t.Error("an error was expected when calling rollback, but got none")
}
}
func TestUnexpectedRollbackOrder(t *testing.T) {
// Open new mock database
db, mock, err := New()
if err != nil {
fmt.Println("error creating mock database")
return
}
mock.ExpectBegin()
mock.ExpectCommit()
tx, _ := db.Begin()
if err := tx.Rollback(); err == nil {
t.Error("an error was expected when calling rollback, but got none")
}
}