mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-23 06:18:02 -05:00
Compare commits
28 Commits
v0.26.0
...
integratio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23d1a90734 | ||
|
|
555528d780 | ||
|
|
2bf2461e9e | ||
|
|
fd26fa4433 | ||
|
|
1225a2f0c0 | ||
|
|
c835af431a | ||
|
|
bde46e1401 | ||
|
|
49d255254c | ||
|
|
eedd0ab67f | ||
|
|
65b21960fa | ||
|
|
6ff567df47 | ||
|
|
cc3c52731d | ||
|
|
87ff9150d2 | ||
|
|
81b42ac973 | ||
|
|
be7560f606 | ||
|
|
edaa1c23cf | ||
|
|
0cfac2984e | ||
|
|
0b7ffa4364 | ||
|
|
ca4a12b5f3 | ||
|
|
7d5af5f001 | ||
|
|
2bcfca0981 | ||
|
|
3932efbd4b | ||
|
|
1bfe394222 | ||
|
|
96904e28e9 | ||
|
|
c3c2cec9ab | ||
|
|
1a39de7617 | ||
|
|
edf8377c57 | ||
|
|
fd4250d0db |
@@ -214,12 +214,15 @@ func AddPostgresPrebuiltConfig(t *testing.T, config map[string]any) map[string]a
|
||||
PostgresListDatabaseStatsToolKind = "postgres-list-database-stats"
|
||||
PostgresListRolesToolKind = "postgres-list-roles"
|
||||
PostgresListStoredProcedureToolKind = "postgres-list-stored-procedure"
|
||||
|
||||
|
||||
)
|
||||
|
||||
tools, ok := config["tools"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("unable to get tools from config")
|
||||
}
|
||||
|
||||
tools["list_tables"] = map[string]any{
|
||||
"kind": PostgresListTablesToolKind,
|
||||
"source": "my-instance",
|
||||
@@ -943,6 +946,8 @@ func TestCloudSQLMySQL_IPTypeParsingFromYAML(t *testing.T) {
|
||||
|
||||
// Finds and drops all tables in a postgres database.
|
||||
func CleanupPostgresTables(t *testing.T, ctx context.Context, pool *pgxpool.Pool) {
|
||||
|
||||
t.Logf("in cleanupPostgrestTables");
|
||||
query := `
|
||||
SELECT table_name FROM information_schema.tables
|
||||
WHERE table_schema = 'public' AND table_type = 'BASE TABLE';`
|
||||
@@ -964,14 +969,31 @@ func CleanupPostgresTables(t *testing.T, ctx context.Context, pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
if len(tablesToDrop) == 0 {
|
||||
t.Logf("No tables to drop in 'public' schema")
|
||||
return
|
||||
}
|
||||
|
||||
t.Logf("Tables to drop in 'public' schema: %s", strings.Join(tablesToDrop, ", "))
|
||||
|
||||
dropQuery := fmt.Sprintf("DROP TABLE IF EXISTS %s CASCADE;", strings.Join(tablesToDrop, ", "))
|
||||
|
||||
if _, err := pool.Exec(ctx, dropQuery); err != nil {
|
||||
t.Fatalf("Failed to drop all tables in 'public' schema: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("Dropped tables in 'public' schema: %s", strings.Join(tablesToDrop, ", "))
|
||||
|
||||
|
||||
// // 1. Drop the entire public schema (this kills tables, views, types, etc.)
|
||||
// dropSchema := "DROP SCHEMA public CASCADE;"
|
||||
// // 2. Recreate the empty public schema
|
||||
// createSchema := "CREATE SCHEMA public;"
|
||||
// // 3. Grant permissions back (Postgres default)
|
||||
// grantPublic := "GRANT ALL ON SCHEMA public TO public;"
|
||||
|
||||
// _, err := pool.Exec(ctx, dropSchema + createSchema + grantPublic)
|
||||
// if err != nil {
|
||||
// t.Fatalf("Failed to nuclear-wipe the public schema: %v", err)
|
||||
// }
|
||||
}
|
||||
|
||||
// Finds and drops all tables in a mysql database.
|
||||
|
||||
@@ -81,6 +81,25 @@ func initPostgresConnectionPool(host, port, user, pass, dbname string) (*pgxpool
|
||||
return pool, nil
|
||||
}
|
||||
|
||||
func CreateIsolatedSchema(t *testing.T, ctx context.Context, pool *pgxpool.Pool) (string, func()) {
|
||||
|
||||
schemaName := "test_schema_" + strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
|
||||
_, err := pool.Exec(ctx, fmt.Sprintf("CREATE SCHEMA %q;", schemaName))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create sandbox schema: %v", err)
|
||||
}
|
||||
|
||||
cleanup := func() {
|
||||
// Use Background context to ensure cleanup runs even if the test timed out
|
||||
_, err := pool.Exec(context.Background(), fmt.Sprintf("DROP SCHEMA %q CASCADE;", schemaName))
|
||||
if err != nil {
|
||||
t.Logf("Cleanup warning: failed to drop schema %s: %v", schemaName, err)
|
||||
}
|
||||
}
|
||||
|
||||
return schemaName, cleanup
|
||||
}
|
||||
func TestPostgres(t *testing.T) {
|
||||
sourceConfig := getPostgresVars(t)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
@@ -92,9 +111,20 @@ func TestPostgres(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create postgres connection pool: %s", err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
//this was conflicting and too slow
|
||||
// cleanup test environment
|
||||
tests.CleanupPostgresTables(t, ctx, pool)
|
||||
// tests.CleanupPostgresTables(t, ctx, pool)
|
||||
|
||||
schemaName, cleanupSchema := CreateIsolatedSchema(t, ctx, pool)
|
||||
defer cleanupSchema()
|
||||
|
||||
// Force the pool to ONLY use this schema for this test run
|
||||
_, err = pool.Exec(ctx, fmt.Sprintf("SET search_path TO %q;", schemaName))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to set search path: %v", err)
|
||||
}
|
||||
|
||||
// create table name with UUID
|
||||
tableNameParam := "param_table_" + strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
|
||||
Reference in New Issue
Block a user