Skip to content

test: verify db_owner wiring and CreateUserRole with built-in PG roles#345

Merged
rshoemaker merged 1 commit intomainfrom
test/PLAT-550-551/db-owner-and-role-verification
Apr 15, 2026
Merged

test: verify db_owner wiring and CreateUserRole with built-in PG roles#345
rshoemaker merged 1 commit intomainfrom
test/PLAT-550-551/db-owner-and-role-verification

Conversation

@rshoemaker
Copy link
Copy Markdown
Contributor

@rshoemaker rshoemaker commented Apr 14, 2026

Summary

  • Add unit tests verifying db_owner and CreateUserRole with built-in PostgreSQL roles work as expected for the connect_as design
  • No code changes — tests only

Test plan

  • TestSpec_NodeInstances_DBOwner — single owner propagated, no owner is empty, multiple owners rejected, owner propagates to all nodes
  • TestCreateUserRole_BuiltinPgRolespg_read_all_data, pg_read_all_settings, pg_read_all_stats produce correct GRANT statements
  • Full test suite passes (1005 tests)

PLAT-550
PLAT-551

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.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Added comprehensive test coverage for database owner propagation in NodeInstances() and for creating user roles with built-in PostgreSQL roles. Both additions validate existing behavior through new test cases without modifying production code.

Changes

Cohort / File(s) Summary
Database Owner Propagation Tests
server/internal/database/spec_test.go
Added TestSpec_NodeInstances_DBOwner test suite with four cases validating DBOwner propagation to node instances, including single owner, no owner, multiple owners (error), and multiple nodes scenarios.
PostgreSQL Built-in Role Tests
server/internal/postgres/roles_test.go
Added test case to TestCreateUserRole validating user role creation with built-in PostgreSQL roles, verifying conditional role creation and grant statements.

Poem

🐰 Tests hopping in with watchful eyes,
Database owners of proper size!
PostgreSQL roles now tested and blessed,
Coverage complete, we've passed the test!
Quality assured, our code shines bright!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: adding tests for db_owner wiring and CreateUserRole with built-in PostgreSQL roles, directly matching the changeset.
Description check ✅ Passed The description covers Summary, Test plan with specific test cases, and references linked issues, but lacks sections for Changes, Testing commands, and a formal Checklist.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/PLAT-550-551/db-owner-and-role-verification

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
server/internal/database/spec_test.go (1)

527-567: Use require for precondition assertions to avoid panic-masked failures.

At Lines 533, 543, 553, and 563-564, assert.* is non-fatal; subsequent nodes[0], nodes[1], and err.Error() can panic if preconditions fail. Prefer require.* 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2fc886f and 382169b.

📒 Files selected for processing (2)
  • server/internal/database/spec_test.go
  • server/internal/postgres/roles_test.go

@rshoemaker rshoemaker merged commit 628ae6a into main Apr 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants