Branch tests for nil context
This commit is contained in:
@@ -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]))
|
||||
}
|
||||
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user