Skip to content

fix: fix dormancy notifications #14029

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

Merged
merged 16 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove sqlc query in favor of inline sql for tests
  • Loading branch information
BrunoQuaresma committed Jul 26, 2024
commit 5da37456d59ddf57775020f209a03230902ed32d
7 changes: 0 additions & 7 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,13 +1484,6 @@ func (q *querier) GetNotificationMessagesByStatus(ctx context.Context, arg datab
return q.db.GetNotificationMessagesByStatus(ctx, arg)
}

func (q *querier) GetNotificationTemplateByID(ctx context.Context, id uuid.UUID) (database.NotificationTemplate, error) {
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
return database.NotificationTemplate{}, err
}
return q.db.GetNotificationTemplateByID(ctx, id)
}

func (q *querier) GetNotificationsSettings(ctx context.Context) (string, error) {
// No authz checks
return q.db.GetNotificationsSettings(ctx)
Expand Down
15 changes: 0 additions & 15 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func New() database.Store {
files: make([]database.File, 0),
gitSSHKey: make([]database.GitSSHKey, 0),
notificationMessages: make([]database.NotificationMessage, 0),
notificationTemplates: make([]database.NotificationTemplate, 0),
parameterSchemas: make([]database.ParameterSchema, 0),
provisionerDaemons: make([]database.ProvisionerDaemon, 0),
workspaceAgents: make([]database.WorkspaceAgent, 0),
Expand Down Expand Up @@ -161,7 +160,6 @@ type data struct {
jfrogXRayScans []database.JfrogXrayScan
licenses []database.License
notificationMessages []database.NotificationMessage
notificationTemplates []database.NotificationTemplate
oauth2ProviderApps []database.OAuth2ProviderApp
oauth2ProviderAppSecrets []database.OAuth2ProviderAppSecret
oauth2ProviderAppCodes []database.OAuth2ProviderAppCode
Expand Down Expand Up @@ -2819,19 +2817,6 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
return out, nil
}

func (q *FakeQuerier) GetNotificationTemplateByID(_ context.Context, id uuid.UUID) (database.NotificationTemplate, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, template := range q.notificationTemplates {
if template.ID == id {
return template, nil
}
}

return database.NotificationTemplate{}, sql.ErrNoRows
}

func (q *FakeQuerier) GetNotificationsSettings(_ context.Context) (string, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand Down
7 changes: 0 additions & 7 deletions coderd/database/dbmetrics/dbmetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions coderd/database/queries/notifications.sql
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,3 @@ WHERE id IN

-- name: GetNotificationMessagesByStatus :many
SELECT * FROM notification_messages WHERE status = @status LIMIT sqlc.arg('limit')::int;

-- name: GetNotificationTemplateByID :one
SELECT * FROM notification_templates WHERE id = @id::uuid;
13 changes: 7 additions & 6 deletions coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,15 @@ func TestNotifcationTemplatesBody(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
t.Cleanup(cancel)
db, _, _ := dbtestutil.NewDBWithSQLDB(t)
_, _, sql := dbtestutil.NewDBWithSQLDB(t)

tpl, err := db.GetNotificationTemplateByID(ctx, tc.id)
require.NoError(t, err, "failed to get notification template")
var bodyTmpl string
err := sql.
QueryRow("SELECT body_template FROM notification_templates WHERE id = $1 LIMIT 1", tc.id).
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've inlined this query because it's only used for tests now. I don't think the overhead of adding a new SQLC query would be justifiable. I actually tried that, and I encountered a few accounting errors because the query wasn't being used in the non-test codebase.

Scan(&bodyTmpl)
require.NoError(t, err, "failed to query body template for template:", tc.id)

_, err = render.GoTemplate(tpl.BodyTemplate, tc.payload, nil)
_, err = render.GoTemplate(bodyTmpl, tc.payload, nil)
require.NoError(t, err, "failed to render notification template")
})
}
Expand Down
Loading