@@ -12,47 +12,55 @@ import (
12
12
13
13
"github.com/coder/coder/v2/coderd/coderdtest"
14
14
"github.com/coder/coder/v2/coderd/database"
15
+ "github.com/coder/coder/v2/coderd/database/dbmem"
15
16
"github.com/coder/coder/v2/coderd/database/dbtestutil"
17
+ "github.com/coder/coder/v2/coderd/database/pubsub"
16
18
"github.com/coder/coder/v2/coderd/notifications"
17
19
"github.com/coder/coder/v2/codersdk"
18
20
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
19
21
"github.com/coder/coder/v2/testutil"
20
22
)
21
23
22
- func createOpts (t * testing.T ) * coderdenttest.Options {
24
+ func createOpts (t * testing.T , usePostgres bool ) * coderdenttest.Options {
23
25
t .Helper ()
24
26
25
- db , ps := dbtestutil .NewDB (t )
27
+ var (
28
+ db database.Store
29
+ ps pubsub.Pubsub
30
+ )
31
+
32
+ if usePostgres {
33
+ if ! dbtestutil .WillUsePostgres () {
34
+ t .Skip ("This test requires postgres; it relies on read from and writing to the notification_templates table" )
35
+ }
36
+
37
+ db , ps = dbtestutil .NewDB (t )
38
+ } else {
39
+ db , ps = dbmem .New (), pubsub .NewInMemory ()
40
+ }
26
41
27
42
dt := coderdtest .DeploymentValues (t )
28
43
dt .Experiments = []string {string (codersdk .ExperimentNotifications )}
29
44
return & coderdenttest.Options {
30
45
Options : & coderdtest.Options {
31
- DeploymentValues : dt ,
32
-
33
- IncludeProvisionerDaemon : true ,
34
- Database : db ,
35
- Pubsub : ps ,
46
+ DeploymentValues : dt ,
47
+ Database : db ,
48
+ Pubsub : ps ,
36
49
},
37
50
}
38
51
}
39
52
40
53
func TestUpdateNotificationTemplateMethod (t * testing.T ) {
41
54
t .Parallel ()
42
55
43
- if ! dbtestutil .WillUsePostgres () {
44
- t .Skip ("This test requires postgres; it relies on read from and writing to the notification_templates table" )
45
- }
46
-
47
56
t .Run ("Happy path" , func (t * testing.T ) {
48
57
t .Parallel ()
49
58
50
59
ctx := testutil .Context (t , testutil .WaitSuperLong )
51
-
52
- api , _ := coderdenttest .New (t , createOpts (t ))
60
+ api , _ := coderdenttest .New (t , createOpts (t , true ))
53
61
54
62
var (
55
- method = string (database .NotificationMethodSmtp )
63
+ method = string (database .NotificationMethodSmtp )
56
64
templateID = notifications .TemplateWorkspaceDeleted
57
65
)
58
66
@@ -75,10 +83,10 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
75
83
t .Run ("Insufficient permissions" , func (t * testing.T ) {
76
84
t .Parallel ()
77
85
78
- ctx := testutil .Context (t , testutil .WaitSuperLong )
86
+ ctx := testutil .Context (t , testutil .WaitShort )
79
87
80
88
// Given: the first user which has an "owner" role, and another user which does not.
81
- api , firstUser := coderdenttest .New (t , createOpts (t ))
89
+ api , firstUser := coderdenttest .New (t , createOpts (t , false ))
82
90
anotherClient , _ := coderdtest .CreateAnotherUser (t , api , firstUser .OrganizationID )
83
91
84
92
// When: calling the API as an unprivileged user.
@@ -98,7 +106,7 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
98
106
ctx := testutil .Context (t , testutil .WaitSuperLong )
99
107
100
108
// Given: the first user which has an "owner" role
101
- api , _ := coderdenttest .New (t , createOpts (t ))
109
+ api , _ := coderdenttest .New (t , createOpts (t , true ))
102
110
103
111
// When: calling the API with an invalid method.
104
112
const method = "nope"
@@ -119,11 +127,10 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
119
127
t .Parallel ()
120
128
121
129
ctx := testutil .Context (t , testutil .WaitSuperLong )
122
-
123
- api , _ := coderdenttest .New (t , createOpts (t ))
130
+ api , _ := coderdenttest .New (t , createOpts (t , true ))
124
131
125
132
var (
126
- method = string (database .NotificationMethodSmtp )
133
+ method = string (database .NotificationMethodSmtp )
127
134
templateID = notifications .TemplateWorkspaceDeleted
128
135
)
129
136
@@ -170,4 +177,4 @@ func getTemplateById(t *testing.T, ctx context.Context, api *codersdk.Client, id
170
177
}
171
178
172
179
return template , nil
173
- }
180
+ }
0 commit comments