|
1 | 1 | package dbconn_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "context" |
4 | 5 | "database/sql/driver"
|
5 | 6 | "fmt"
|
6 | 7 | "os"
|
@@ -183,6 +184,36 @@ var _ = Describe("dbconn/dbconn tests", func() {
|
183 | 184 | Expect(rowsReturned).To(Equal(int64(1)))
|
184 | 185 | })
|
185 | 186 | })
|
| 187 | + Describe("DBConn.ExecContext", func() { |
| 188 | + It("executes an INSERT outside of a transaction", func() { |
| 189 | + ctx, cancel := context.WithCancel(context.Background()) |
| 190 | + defer cancel() |
| 191 | + |
| 192 | + fakeResult := testhelper.TestResult{Rows: 1} |
| 193 | + mock.ExpectExec("INSERT (.*)").WillReturnResult(fakeResult) |
| 194 | + |
| 195 | + res, err := connection.ExecContext(ctx, "INSERT INTO pg_tables VALUES ('schema', 'table')") |
| 196 | + Expect(err).ToNot(HaveOccurred()) |
| 197 | + rowsReturned, err := res.RowsAffected() |
| 198 | + Expect(rowsReturned).To(Equal(int64(1))) |
| 199 | + }) |
| 200 | + It("executes an INSERT in a transaction", func() { |
| 201 | + ctx, cancel := context.WithCancel(context.Background()) |
| 202 | + defer cancel() |
| 203 | + |
| 204 | + fakeResult := testhelper.TestResult{Rows: 1} |
| 205 | + ExpectBegin(mock) |
| 206 | + mock.ExpectExec("INSERT (.*)").WillReturnResult(fakeResult) |
| 207 | + mock.ExpectCommit() |
| 208 | + |
| 209 | + connection.MustBegin() |
| 210 | + res, err := connection.ExecContext(ctx, "INSERT INTO pg_tables VALUES ('schema', 'table')") |
| 211 | + connection.MustCommit() |
| 212 | + Expect(err).ToNot(HaveOccurred()) |
| 213 | + rowsReturned, err := res.RowsAffected() |
| 214 | + Expect(rowsReturned).To(Equal(int64(1))) |
| 215 | + }) |
| 216 | + }) |
186 | 217 | Describe("DBConn.Get", func() {
|
187 | 218 | It("executes a GET outside of a transaction", func() {
|
188 | 219 | two_col_single_row := sqlmock.NewRows([]string{"schemaname", "tablename"}).
|
|
0 commit comments