Same as the above, but non-parallel so tests can use `t.Setenv`. Separated out into its own test block so that we don't have to mark the entire block above as non-parallel because a few tests can't be made parallel.
(t *testing.T)
| 237 | // out into its own test block so that we don't have to mark the entire block |
| 238 | // above as non-parallel because a few tests can't be made parallel. |
| 239 | func TestBaseCommandSetNonParallel(t *testing.T) { |
| 240 | ctx := context.Background() |
| 241 | |
| 242 | type testBundle struct { |
| 243 | out *bytes.Buffer |
| 244 | } |
| 245 | |
| 246 | setup := func(t *testing.T) (*cobra.Command, *testBundle) { |
| 247 | t.Helper() |
| 248 | |
| 249 | cli := NewCLI(&Config{ |
| 250 | Name: "River", |
| 251 | }) |
| 252 | |
| 253 | var out bytes.Buffer |
| 254 | cli.SetOut(&out) |
| 255 | |
| 256 | return cli.BaseCommandSet(), &testBundle{ |
| 257 | out: &out, |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | t.Run("PGEnvWithoutDatabaseURL", func(t *testing.T) { |
| 262 | cmd, _ := setup(t) |
| 263 | |
| 264 | testDatabaseURL := riversharedtest.TestDatabaseURL() |
| 265 | |
| 266 | config, err := pgxpool.ParseConfig(testDatabaseURL) |
| 267 | require.NoError(t, err) |
| 268 | |
| 269 | dbPool, err := pgxpool.NewWithConfig(ctx, config) |
| 270 | require.NoError(t, err) |
| 271 | |
| 272 | var ( |
| 273 | driver = riverpgxv5.New(dbPool) |
| 274 | schema = riverdbtest.TestSchema(ctx, t, driver, nil) |
| 275 | ) |
| 276 | |
| 277 | t.Setenv("TEST_DATABASE_URL", "") |
| 278 | |
| 279 | parsedURL, err := url.Parse(testDatabaseURL) |
| 280 | require.NoError(t, err) |
| 281 | |
| 282 | t.Setenv("PGDATABASE", parsedURL.Path[1:]) |
| 283 | t.Setenv("PGHOST", parsedURL.Hostname()) |
| 284 | pass, _ := parsedURL.User.Password() |
| 285 | t.Setenv("PGPASSWORD", pass) |
| 286 | t.Setenv("PGPORT", cmp.Or(parsedURL.Port(), "5432")) |
| 287 | t.Setenv("PGSSLMODE", parsedURL.Query().Get("sslmode")) |
| 288 | t.Setenv("PGUSER", parsedURL.User.Username()) |
| 289 | |
| 290 | cmd.SetArgs([]string{"migrate-up", "--schema", schema}) |
| 291 | require.NoError(t, cmd.Execute()) |
| 292 | }) |
| 293 | } |
| 294 | |
| 295 | func TestBaseCommandSetPostgresTimeoutPrecedence(t *testing.T) { |
| 296 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…