unit tests for postgres database#1793
Draft
DmytroPI-dev wants to merge 1 commit intofeature/database-controllersfrom
Draft
unit tests for postgres database#1793DmytroPI-dev wants to merge 1 commit intofeature/database-controllersfrom
DmytroPI-dev wants to merge 1 commit intofeature/database-controllersfrom
Conversation
mploski
reviewed
Mar 25, 2026
| } | ||
|
|
||
| got := managedRoleOwners(managedFields) | ||
| want := map[string]string{ |
Collaborator
There was a problem hiding this comment.
In general want should be a part of Arrange if we want to follow AAA pattern - this is general comment
mploski
reviewed
Mar 25, 2026
| Status: enterprisev4.PostgresClusterStatus{ | ||
| Phase: func() *string { | ||
| v := string(ClusterReady) | ||
| return &v |
Collaborator
There was a problem hiding this comment.
why do we need this, maybe we can also levarage Ptr helper function strPtr(s string) *string
mploski
reviewed
Mar 25, 2026
|
|
||
| require.Len(t, got.retained, 2) | ||
| require.Len(t, got.deleted, 1) | ||
| assert.Equal(t, "payments", got.retained[0].Name) |
Collaborator
There was a problem hiding this comment.
can we levarage assert.ElementsMatch to avoid hardcoding the order?
mploski
reviewed
Mar 25, 2026
| Name: "primary-payments-admin", | ||
| Namespace: "dbs", | ||
| Annotations: map[string]string{annotationRetainedFrom: postgresDB.Name}, | ||
| OwnerReferences: []metav1.OwnerReference{ |
Collaborator
There was a problem hiding this comment.
since you wan to test retained secret, shouldn't owner references be empty?
Author
There was a problem hiding this comment.
In database.go, in orphanSecret method, we have the following:
- Fetch the secret
- if
secret.Annotations[annotationRetainedFrom] == postgresDB.Name, wecontinueimmediately, and only otherwise it strips owner ref and add annotation.
So for this specific test, the point is to verify the early-return path: if a secret is already marked retained, the helper should leave it alone. Leaving an owner reference in the fixture might be useful, as it proves the function did not mutate the object. If there would be empty owner ref, test would not show if helper truly skipped mutation.
mploski
reviewed
Mar 25, 2026
| } | ||
|
|
||
| newDBRepo := func(_ context.Context, host, dbName, password string) (DBRepo, error) { | ||
| assert.Equal(t, "rw.example.internal", host) |
Collaborator
There was a problem hiding this comment.
do we need this asserts here? what is the benefit?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Unit tests for postgresql/database/core
Key Changes
Add database_unit_test.go
Testing and Verification
The PR is for adding unit tests.
Related Issues
CPI-1915
PR Checklist