MCPcopy Index your code
hub / github.com/riverqueue/river / TestBaseCommandSetNonParallel

Function TestBaseCommandSetNonParallel

cmd/river/rivercli/river_cli_test.go:239–293  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
239func 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
295func TestBaseCommandSetPostgresTimeoutPrecedence(t *testing.T) {
296 t.Parallel()

Callers

nothing calls this directly

Calls 10

SetOutMethod · 0.95
BaseCommandSetMethod · 0.95
TestDatabaseURLFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
NewCLIFunction · 0.85
ExecuteMethod · 0.80
HelperMethod · 0.65
RunMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…