Skip to content

Commit bc721f7

Browse files
committed
fix: test
1 parent 09c5718 commit bc721f7

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

crates/pgls_splinter/tests/diagnostics.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use pgls_console::fmt::{Formatter, HTML};
22
use pgls_diagnostics::{Diagnostic, LogCategory, Visit};
3-
use pgls_splinter::{SplinterParams, run_splinter};
3+
use pgls_splinter::{run_splinter, SplinterParams};
44
use sqlx::PgPool;
55
use std::fmt::Write;
66
use std::io;
@@ -52,26 +52,19 @@ struct TestSetup<'a> {
5252
impl TestSetup<'_> {
5353
async fn test(self) {
5454
// Create Supabase-specific roles that splinter expects
55-
sqlx::raw_sql(
56-
r#"
57-
do $$
58-
begin
59-
if not exists (select from pg_roles where rolname = 'anon') then
60-
create role anon nologin;
61-
end if;
62-
if not exists (select from pg_roles where rolname = 'authenticated') then
63-
create role authenticated nologin;
64-
end if;
65-
if not exists (select from pg_roles where rolname = 'service_role') then
66-
create role service_role nologin;
67-
end if;
68-
end
69-
$$;
70-
"#,
71-
)
72-
.execute(self.test_db)
73-
.await
74-
.expect("Failed to create Supabase roles");
55+
for role in ["anon", "authenticated", "service_role"] {
56+
let result = sqlx::query(&format!("CREATE ROLE {role} NOLOGIN"))
57+
.execute(self.test_db)
58+
.await;
59+
60+
// Ignore duplicate role errors
61+
if let Err(sqlx::Error::Database(db_err)) = &result {
62+
let code = db_err.code();
63+
if code.as_deref() != Some("23505") && code.as_deref() != Some("42710") {
64+
result.expect("Failed to create Supabase roles");
65+
}
66+
}
67+
}
7568

7669
// Run setup SQL
7770
sqlx::raw_sql(self.setup)

0 commit comments

Comments
 (0)