MCPcopy Index your code
hub / github.com/coder/coder / TestConnectToPostgres

Function TestConnectToPostgres

cli/server_test.go:2421–2468  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2419}
2420
2421func TestConnectToPostgres(t *testing.T) {
2422 t.Parallel()
2423
2424 t.Run("Migrate", func(t *testing.T) {
2425 t.Parallel()
2426
2427 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2428 t.Cleanup(cancel)
2429
2430 log := testutil.Logger(t)
2431
2432 dbURL, err := dbtestutil.Open(t)
2433 require.NoError(t, err)
2434
2435 sqlDB, err := cli.ConnectToPostgres(ctx, log, "postgres", dbURL, migrations.Up)
2436 require.NoError(t, err)
2437 t.Cleanup(func() {
2438 _ = sqlDB.Close()
2439 })
2440 require.NoError(t, sqlDB.PingContext(ctx))
2441 })
2442
2443 t.Run("NoMigrate", func(t *testing.T) {
2444 t.Parallel()
2445
2446 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2447 t.Cleanup(cancel)
2448
2449 log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
2450
2451 dbURL, err := dbtestutil.Open(t)
2452 require.NoError(t, err)
2453
2454 okDB, err := cli.ConnectToPostgres(ctx, log, "postgres", dbURL, nil)
2455 require.NoError(t, err)
2456 defer okDB.Close()
2457
2458 // Set the migration number forward
2459 _, err = okDB.Exec(`UPDATE schema_migrations SET version = version + 1`)
2460 require.NoError(t, err)
2461
2462 _, err = cli.ConnectToPostgres(ctx, log, "postgres", dbURL, nil)
2463 require.Error(t, err)
2464 require.ErrorContains(t, err, "database needs migration")
2465
2466 require.NoError(t, okDB.PingContext(ctx))
2467 })
2468}
2469
2470func TestServer_DisabledDERP_EmptyBaseMap(t *testing.T) {
2471 t.Parallel()

Callers

nothing calls this directly

Calls 8

LoggerFunction · 0.92
OpenFunction · 0.92
ConnectToPostgresFunction · 0.92
RunMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected