Skip to content

Commit 298bfde

Browse files
committed
add tests
1 parent aaceb21 commit 298bfde

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

sqlmock_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,3 +1113,31 @@ func TestExecExpectationErrorDelay(t *testing.T) {
11131113
t.Errorf("expecting a delay of less than %v before error, actual delay was %v", delay, elapsed)
11141114
}
11151115
}
1116+
1117+
func TestOptionsFail(t *testing.T) {
1118+
t.Parallel()
1119+
expected := errors.New("failing option")
1120+
option := func(*sqlmock) error {
1121+
return expected
1122+
}
1123+
db, _, err := New(option)
1124+
defer db.Close()
1125+
if err == nil {
1126+
t.Errorf("missing expecting error '%s' when opening a stub database connection", expected)
1127+
}
1128+
}
1129+
1130+
func TestNewRows(t *testing.T) {
1131+
t.Parallel()
1132+
db, mock, err := New()
1133+
if err != nil {
1134+
t.Errorf("an error '%s' was not expected when opening a stub database connection", err)
1135+
}
1136+
defer db.Close()
1137+
columns := []string{"col1", "col2"}
1138+
1139+
r := mock.NewRows(columns)
1140+
if len(r.cols) != len(columns) || r.cols[0] != columns[0] || r.cols[1] != columns[1] {
1141+
t.Errorf("expecting to create a row with columns %v, actual colmns are %v", r.cols, columns)
1142+
}
1143+
}

0 commit comments

Comments
 (0)