-
Notifications
You must be signed in to change notification settings - Fork 931
chore: use idiomatic test setup in notification tests #14416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Danny Kopping <[email protected]>
coderd/database/dbauthz/dbauthz.go
Outdated
rbac.ResourceDeploymentConfig.Type: {policy.ActionCreate, policy.ActionUpdate, policy.ActionDelete}, | ||
rbac.ResourceNotificationTemplate.Type: {policy.ActionCreate, policy.ActionUpdate, policy.ActionDelete}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two permissions were necessary, and since tests using setupInMemory
never hit dbauthz
we never encountered this mismatch of permissions.
@@ -723,19 +732,6 @@ func TestNotificationTemplatesCanRender(t *testing.T) { | |||
}, | |||
}, | |||
}, | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test did not belong here.
17949db
to
6a28ab0
Compare
Signed-off-by: Danny Kopping <[email protected]>
6a28ab0
to
148fac8
Compare
|
||
// WHEN: notifications are enqueued which should succeed and fail | ||
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"nice": "true"}, "") // Will succeed. | ||
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"nice": "true", "i": "0"}, "") // Will succeed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typical problem here: not all the business logic was in dbmem, so the pg server rejects duplicate notifications and we needed to avoid that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Looking back at the tests I implemented a while back for notifications, I realized the way I was setting up the database was wrong - or at least incomplete. I'm more familiar with our testing idioms now and this was bugging me.
setup
andsetupInMemory
are both covered bycoderdtest.New
, depending on what theDB_FROM
andDB
environment variables are.This doesn't really change anything for tests which used
setup
(since those were previously and will still provision a postgres instance to test against), but for thesetupInMemory
cases it now actually tests them against a real database when we runmake test-postgres
; previously they were only running in-memory.This PR also includes a couple other minor drive-by fixes, which I've called out below.