TestConnectOAuth is separate from other connect tests because it specifically needs a configured OAuthTokenProvider. Further it's only available in Postgres 18+ and requires the dummy OAuth validator module installed.
(t *testing.T)
| 255 | // needs a configured OAuthTokenProvider. Further it's only available in Postgres |
| 256 | // 18+ and requires the dummy OAuth validator module installed. |
| 257 | func TestConnectOAuth(t *testing.T) { |
| 258 | if os.Getenv(runOAuthTestEnvVar) != "true" { |
| 259 | t.Skipf("Skipping as '%s=true' is not set", runOAuthTestEnvVar) |
| 260 | } |
| 261 | |
| 262 | config, err := pgconn.ParseConfig("host=127.0.0.1 user=pgx_oauth dbname=pgx_test") |
| 263 | require.NoError(t, err) |
| 264 | |
| 265 | // Configure OAuthTokenProvider for dummy validator. |
| 266 | // The dummy validator accepts any token and maps it to the user equal to the |
| 267 | // token string. |
| 268 | config.OAuthTokenProvider = func(ctx context.Context) (string, error) { |
| 269 | return "pgx_oauth", nil |
| 270 | } |
| 271 | |
| 272 | conn, err := pgconn.ConnectConfig(context.Background(), config) |
| 273 | require.NoError(t, err) |
| 274 | defer closeConn(t, conn) |
| 275 | |
| 276 | result := conn.ExecParams(context.Background(), "SELECT CURRENT_USER", nil, nil, nil, nil).Read() |
| 277 | require.NoError(t, result.Err) |
| 278 | require.Len(t, result.Rows, 1) |
| 279 | require.Len(t, result.Rows[0], 1) |
| 280 | require.Equalf(t, "pgx_oauth", string(result.Rows[0][0]), "not logged in as expected user.") |
| 281 | } |
| 282 | |
| 283 | func TestConnectOAuthError(t *testing.T) { |
| 284 | if os.Getenv(runOAuthTestEnvVar) != "true" { |
nothing calls this directly
no test coverage detected