Skip to content

Commit 8618f59

Browse files
tianzhouclaude
andauthored
fix: clean up leaked cluster-level roles in TestIgnorePrivileges (#346)
* feat: add support for trigger UPDATE OF columns (#342) Triggers with column-specific UPDATE events (e.g., UPDATE OF email) were losing the column specification during inspection, causing incorrect migration plans that would fire triggers on all updates instead of only on specified column changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: guard UPDATE OF column extraction with tgtype bitmask check Only extract UPDATE OF columns when the trigger actually has an UPDATE event, preventing false positives if the substring appears elsewhere. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: clean up leaked cluster-level roles in TestIgnorePrivileges TestIgnorePrivileges creates cluster-level PostgreSQL roles (app_reader, deploy_bot, admin_role) and ALTER DEFAULT PRIVILEGES rules in the shared embedded PG instance. Since Go runs tests alphabetically, these persist and contaminate TestPlanAndApply, causing unexpected GRANT statements in plan output for all table/view/index tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5a900ec commit 8618f59

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

cmd/ignore_integration_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,40 @@ ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO deploy_bot;
11301130
t.Error("Plan should not include changes for admin_role (ignored)")
11311131
}
11321132
})
1133+
1134+
// Clean up cluster-level objects (roles, default privileges) from sharedEmbeddedPG.
1135+
// The plan subtest applies SQL with CREATE ROLE and ALTER DEFAULT PRIVILEGES to the
1136+
// shared embedded PG instance. These are cluster-level objects that persist after the
1137+
// temp schema is dropped, contaminating subsequent tests (e.g., TestPlanAndApply).
1138+
cleanupSharedEmbeddedPG(t)
1139+
}
1140+
1141+
// cleanupSharedEmbeddedPG removes cluster-level objects (roles, default privileges)
1142+
// that were created in sharedEmbeddedPG by privilege tests.
1143+
func cleanupSharedEmbeddedPG(t *testing.T) {
1144+
t.Helper()
1145+
1146+
sharedConn, _, _, _, _, _ := testutil.ConnectToPostgres(t, sharedEmbeddedPG)
1147+
defer sharedConn.Close()
1148+
1149+
// Must clean up in order: revoke default privileges, revoke object privileges, then drop roles.
1150+
// Each statement runs independently since some roles may not exist.
1151+
cleanupStatements := []string{
1152+
"ALTER DEFAULT PRIVILEGES REVOKE ALL ON TABLES FROM app_reader",
1153+
"ALTER DEFAULT PRIVILEGES REVOKE ALL ON TABLES FROM deploy_bot",
1154+
"REASSIGN OWNED BY app_reader TO testuser",
1155+
"DROP OWNED BY app_reader",
1156+
"REASSIGN OWNED BY deploy_bot TO testuser",
1157+
"DROP OWNED BY deploy_bot",
1158+
"REASSIGN OWNED BY admin_role TO testuser",
1159+
"DROP OWNED BY admin_role",
1160+
"DROP ROLE IF EXISTS app_reader",
1161+
"DROP ROLE IF EXISTS deploy_bot",
1162+
"DROP ROLE IF EXISTS admin_role",
1163+
}
1164+
for _, stmt := range cleanupStatements {
1165+
sharedConn.Exec(stmt) // Ignore errors; some roles may not exist
1166+
}
11331167
}
11341168

11351169
// verifyPlanOutput checks that plan output excludes ignored objects

0 commit comments

Comments
 (0)