test: remove unnecessary dbauthz.AsSystemRestricted calls in tests (#22663)

This commit is contained in:
Danielle Maywood
2026-03-05 20:29:49 +00:00
committed by GitHub
parent 25dac6e5f7
commit f91475cd51
11 changed files with 24 additions and 41 deletions
+4 -5
View File
@@ -14,7 +14,6 @@ import (
"golang.org/x/xerrors"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/database/dbgen"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/notifications"
@@ -30,7 +29,6 @@ func TestBufferedUpdates(t *testing.T) {
// setup
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong))
store, ps := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -57,6 +55,7 @@ func TestBufferedUpdates(t *testing.T) {
user := dbgen.User(t, store, database.User{})
// WHEN: notifications are enqueued which should succeed and fail
ctx := testutil.Context(t, testutil.WaitSuperLong)
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"nice": "true", "i": "0"}, "") // Will succeed.
require.NoError(t, err)
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"nice": "true", "i": "1"}, "") // Will succeed.
@@ -106,7 +105,6 @@ func TestBuildPayload(t *testing.T) {
// SETUP
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong))
store, _ := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -146,6 +144,7 @@ func TestBuildPayload(t *testing.T) {
require.NoError(t, err)
// WHEN: a notification is enqueued
ctx := testutil.Context(t, testutil.WaitSuperLong)
_, err = enq.Enqueue(ctx, uuid.New(), notifications.TemplateWorkspaceDeleted, map[string]string{
"name": "my-workspace",
}, "test")
@@ -163,7 +162,6 @@ func TestStopBeforeRun(t *testing.T) {
// SETUP
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong))
store, ps := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -172,6 +170,7 @@ func TestStopBeforeRun(t *testing.T) {
require.NoError(t, err)
// THEN: validate that the manager can be stopped safely without Run() having been called yet
ctx := testutil.Context(t, testutil.WaitSuperLong)
require.Eventually(t, func() bool {
assert.NoError(t, mgr.Stop(ctx))
return true
@@ -183,7 +182,6 @@ func TestRunStopRace(t *testing.T) {
// SETUP
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitMedium))
store, ps := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -194,6 +192,7 @@ func TestRunStopRace(t *testing.T) {
// Start Run and Stop after each other (run does "go loop()").
// This is to catch a (now fixed) race condition where the manager
// would be accessed/stopped while it was being created/starting up.
ctx := testutil.Context(t, testutil.WaitMedium)
mgr.Run(ctx)
err = mgr.Stop(ctx)
require.NoError(t, err)
+5 -5
View File
@@ -18,7 +18,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/notifications"
"github.com/coder/coder/v2/coderd/notifications/dispatch"
@@ -33,7 +32,6 @@ func TestMetrics(t *testing.T) {
// SETUP
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong))
store, pubsub := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -57,6 +55,7 @@ func TestMetrics(t *testing.T) {
mgr, err := notifications.NewManager(cfg, store, pubsub, defaultHelpers(), metrics, logger.Named("manager"))
require.NoError(t, err)
ctx := testutil.Context(t, testutil.WaitSuperLong)
t.Cleanup(func() {
assert.NoError(t, mgr.Stop(ctx))
})
@@ -221,7 +220,6 @@ func TestPendingUpdatesMetric(t *testing.T) {
t.Parallel()
// SETUP
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong))
store, pubsub := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -247,6 +245,7 @@ func TestPendingUpdatesMetric(t *testing.T) {
mgr, err := notifications.NewManager(cfg, interceptor, pubsub, defaultHelpers(), metrics, logger.Named("manager"),
notifications.WithTestClock(mClock))
require.NoError(t, err)
ctx := testutil.Context(t, testutil.WaitSuperLong)
t.Cleanup(func() {
assert.NoError(t, mgr.Stop(ctx))
})
@@ -314,7 +313,6 @@ func TestInflightDispatchesMetric(t *testing.T) {
t.Parallel()
// SETUP
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong))
store, pubsub := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -333,6 +331,7 @@ func TestInflightDispatchesMetric(t *testing.T) {
mgr, err := notifications.NewManager(cfg, store, pubsub, defaultHelpers(), metrics, logger.Named("manager"))
require.NoError(t, err)
ctx := testutil.Context(t, testutil.WaitSuperLong)
t.Cleanup(func() {
assert.NoError(t, mgr.Stop(ctx))
})
@@ -386,7 +385,6 @@ func TestInflightDispatchesMetric(t *testing.T) {
func TestCustomMethodMetricCollection(t *testing.T) {
t.Parallel()
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong))
store, pubsub := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
@@ -402,6 +400,8 @@ func TestCustomMethodMetricCollection(t *testing.T) {
defaultMethod = database.NotificationMethodSmtp
)
ctx := testutil.Context(t, testutil.WaitSuperLong)
// GIVEN: a template whose notification method differs from the default.
out, err := store.UpdateNotificationTemplateMethodByID(ctx, database.UpdateNotificationTemplateMethodByIDParams{
ID: tmpl,
+2 -2
View File
@@ -1472,12 +1472,12 @@ func TestNotificationTemplates_Golden(t *testing.T) {
// as appearance changes are enterprise features and we do not want to mix those
// can't use the api
if tc.appName != "" {
err = (*db).UpsertApplicationName(dbauthz.AsSystemRestricted(ctx), "Custom Application")
err = (*db).UpsertApplicationName(ctx, "Custom Application")
require.NoError(t, err)
}
if tc.logoURL != "" {
err = (*db).UpsertLogoURL(dbauthz.AsSystemRestricted(ctx), "https://custom.application/logo.png")
err = (*db).UpsertLogoURL(ctx, "https://custom.application/logo.png")
require.NoError(t, err)
}