MCPcopy Create free account
hub / github.com/Permify/permify / createTestDatabaseWithMigrations

Function createTestDatabaseWithMigrations

pkg/database/postgres/repair_test.go:318–422  ·  view source on GitHub ↗

createTestDatabaseWithMigrations creates a test database instance with migrations

()

Source from the content-addressed store, hash-verified

316
317// createTestDatabaseWithMigrations creates a test database instance with migrations
318func createTestDatabaseWithMigrations() (*Postgres, testcontainers.Container, error) {
319 ctx := context.Background()
320
321 image := "postgres:15-alpine"
322
323 container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
324 ContainerRequest: testcontainers.ContainerRequest{
325 Image: image,
326 ExposedPorts: []string{"5432/tcp"},
327 Env: map[string]string{
328 "POSTGRES_USER": "postgres",
329 "POSTGRES_PASSWORD": "postgres",
330 "POSTGRES_DB": "permify",
331 },
332 WaitingFor: wait.ForAll(
333 wait.ForLog("database system is ready to accept connections"),
334 wait.ForListeningPort("5432/tcp"),
335 ),
336 },
337 Started: true,
338 })
339 if err != nil {
340 return nil, nil, err
341 }
342
343 // Enable track_commit_timestamp for XID tracking
344 _, _, execErr := container.Exec(ctx, []string{"psql", "-U", "postgres", "-c", "ALTER SYSTEM SET track_commit_timestamp = on;"})
345 if execErr != nil {
346 container.Terminate(ctx)
347 return nil, nil, execErr
348 }
349
350 // Restart container to apply the setting
351 stopTimeout := 2 * time.Second
352 err = container.Stop(context.Background(), &stopTimeout)
353 if err != nil {
354 container.Terminate(ctx)
355 return nil, nil, err
356 }
357
358 err = container.Start(context.Background())
359 if err != nil {
360 container.Terminate(ctx)
361 return nil, nil, err
362 }
363
364 // Get connection details
365 host, err := container.Host(ctx)
366 if err != nil {
367 container.Terminate(ctx)
368 return nil, nil, err
369 }
370
371 port, err := container.MappedPort(ctx, "5432")
372 if err != nil {
373 container.Terminate(ctx)
374 return nil, nil, err
375 }

Callers 1

repair_test.goFile · 0.85

Calls 6

MaxOpenConnectionsFunction · 0.85
MaxIdleConnectionsFunction · 0.85
MaxConnectionIdleTimeFunction · 0.85
MaxConnectionLifeTimeFunction · 0.85
StartMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected