2
0

Branch tests for nil context

This commit is contained in:
bakape
2020-01-01 14:36:38 +02:00
parent 7196234521
commit 4d345164f1
3 changed files with 818 additions and 708 deletions
+2 -2
View File
@@ -11,13 +11,13 @@ low-level access to PostgreSQL functionality.
## Example Usage
```go
pgConn, err := pgconn.Connect(context.Background(), os.Getenv("DATABASE_URL"))
pgConn, err := pgconn.Connect(nil, os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatalln("pgconn failed to connect:", err)
}
defer pgConn.Close()
result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
result := pgConn.ExecParams(nil, "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
for result.NextRow() {
fmt.Println("User 123 has email:", string(result.Values()[0]))
}
+22
View File
@@ -29,3 +29,25 @@ func ensureConnValid(t *testing.T, pgConn *pgconn.PgConn) {
assert.Equal(t, "2", string(result.Rows[1][0]))
assert.Equal(t, "3", string(result.Rows[2][0]))
}
// Run subtest both with a context.Background() and nil context
func splitOnContext(t *testing.T, test func(t *testing.T, ctx context.Context)) {
t.Helper()
cases := [...]struct {
name string
ctx context.Context
}{
{"background context", context.Background()},
{"nil context", nil},
}
for i := range cases {
c := cases[i]
t.Run(c.name, func(t *testing.T) {
t.Helper()
t.Parallel()
test(t, c.ctx)
})
}
}
+794 -706
View File
File diff suppressed because it is too large Load Diff