MCPcopy
hub / github.com/autobrr/qui / openPostgresTestSchema

Function openPostgresTestSchema

internal/database/postgres_integration_test.go:175–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

173}
174
175func openPostgresTestSchema(t *testing.T) (context.Context, string) {
176 t.Helper()
177
178 baseDSN := strings.TrimSpace(os.Getenv("QUI_TEST_POSTGRES_DSN"))
179 if baseDSN == "" {
180 t.Skip("QUI_TEST_POSTGRES_DSN not set")
181 }
182
183 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
184 t.Cleanup(cancel)
185
186 adminPool, err := pgxpool.New(ctx, baseDSN)
187 require.NoError(t, err)
188 t.Cleanup(adminPool.Close)
189
190 schemaName := fmt.Sprintf("qui_test_%d", time.Now().UnixNano())
191 _, err = adminPool.Exec(ctx, "CREATE SCHEMA "+quoteIdent(schemaName))
192 require.NoError(t, err)
193 t.Cleanup(func() {
194 _, _ = adminPool.Exec(context.Background(), fmt.Sprintf("DROP SCHEMA %s CASCADE", quoteIdent(schemaName)))
195 })
196
197 return ctx, dsnWithSearchPath(t, baseDSN, schemaName)
198}
199
200func dsnWithSearchPath(t *testing.T, dsn string, schema string) string {
201 t.Helper()

Calls 3

quoteIdentFunction · 0.85
dsnWithSearchPathFunction · 0.85
CleanupMethod · 0.80

Tested by

no test coverage detected