test: verify db_owner wiring and CreateUserRole with built-in PG roles#345
Conversation
Add TestSpec_NodeInstances_DBOwner to verify the db_owner → ALTER DATABASE OWNER TO chain: single owner propagation, multiple owner rejection, empty owner handling, and multi-node propagation. Add TestCreateUserRole_BuiltinPgRoles to verify that CreateUserRole correctly generates GRANT statements for built-in PostgreSQL roles like pg_read_all_data, pg_read_all_settings, and pg_read_all_stats.
📝 WalkthroughWalkthroughAdded comprehensive test coverage for database owner propagation in Changes
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/internal/database/spec_test.go (1)
527-567: Userequirefor precondition assertions to avoid panic-masked failures.At Lines 533, 543, 553, and 563-564,
assert.*is non-fatal; subsequentnodes[0],nodes[1], anderr.Error()can panic if preconditions fail. Preferrequire.*for those gates.Suggested change
import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" @@ t.Run("single db_owner is propagated", func(t *testing.T) { @@ nodes, err := spec.NodeInstances() - assert.NoError(t, err) + require.NoError(t, err) + require.Len(t, nodes, 1) assert.Equal(t, "app", nodes[0].DatabaseOwner) }) @@ t.Run("no db_owner results in empty owner", func(t *testing.T) { @@ nodes, err := spec.NodeInstances() - assert.NoError(t, err) + require.NoError(t, err) + require.Len(t, nodes, 1) assert.Empty(t, nodes[0].DatabaseOwner) }) @@ t.Run("multiple db_owners returns error", func(t *testing.T) { @@ _, err := spec.NodeInstances() - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, err.Error(), "only one user can have db_owner=true") }) @@ t.Run("owner propagates to all nodes", func(t *testing.T) { @@ nodes, err := spec.NodeInstances() - assert.NoError(t, err) - assert.Len(t, nodes, 2) + require.NoError(t, err) + require.Len(t, nodes, 2) assert.Equal(t, "app", nodes[0].DatabaseOwner) assert.Equal(t, "app", nodes[1].DatabaseOwner) })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/internal/database/spec_test.go` around lines 527 - 567, The tests use non-fatal assert.* checks before indexing nodes or calling err.Error(), which can mask failures and cause panics; in the four subtests ("single db_owner is propagated", "no db_owner results in empty owner", "multiple db_owners returns error", "owner propagates to all nodes") replace the gating assertions with require.* so failures stop the test before accessing nodes/err. Concretely, use require.NoError(t, err) instead of assert.NoError, use require.Len/require.Empty/require.Equal where the test indexes nodes or reads values (e.g. nodes[0], nodes[1]) and use require.Error + require.Contains (or require.Contains on err.Error()) in the multiple-owner case; update calls around the NodeInstances(), minimalSpec(...) and nodes checks accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@server/internal/database/spec_test.go`:
- Around line 527-567: The tests use non-fatal assert.* checks before indexing
nodes or calling err.Error(), which can mask failures and cause panics; in the
four subtests ("single db_owner is propagated", "no db_owner results in empty
owner", "multiple db_owners returns error", "owner propagates to all nodes")
replace the gating assertions with require.* so failures stop the test before
accessing nodes/err. Concretely, use require.NoError(t, err) instead of
assert.NoError, use require.Len/require.Empty/require.Equal where the test
indexes nodes or reads values (e.g. nodes[0], nodes[1]) and use require.Error +
require.Contains (or require.Contains on err.Error()) in the multiple-owner
case; update calls around the NodeInstances(), minimalSpec(...) and nodes checks
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a7164268-f773-49ff-beac-51a2062f287c
📒 Files selected for processing (2)
server/internal/database/spec_test.goserver/internal/postgres/roles_test.go
Summary
db_ownerandCreateUserRolewith built-in PostgreSQL roles work as expected for theconnect_asdesignTest plan
TestSpec_NodeInstances_DBOwner— single owner propagated, no owner is empty, multiple owners rejected, owner propagates to all nodesTestCreateUserRole_BuiltinPgRoles—pg_read_all_data,pg_read_all_settings,pg_read_all_statsproduce correct GRANT statementsPLAT-550
PLAT-551