@@ -3,7 +3,6 @@ package license_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "strings"
7
6
"testing"
8
7
"time"
9
8
@@ -19,17 +18,13 @@ import (
19
18
20
19
func TestEntitlements (t * testing.T ) {
21
20
t .Parallel ()
22
- all := map [string ]bool {
23
- codersdk .FeatureAuditLog : true ,
24
- codersdk .FeatureBrowserOnly : true ,
25
- codersdk .FeatureSCIM : true ,
26
- codersdk .FeatureHighAvailability : true ,
27
- codersdk .FeatureTemplateRBAC : true ,
28
- codersdk .FeatureMultipleGitAuth : true ,
29
- codersdk .FeatureExternalProvisionerDaemons : true ,
30
- codersdk .FeatureAppearance : true ,
21
+ all := make (map [codersdk.FeatureName ]bool )
22
+ for _ , n := range codersdk .FeatureNames {
23
+ all [n ] = true
31
24
}
32
25
26
+ empty := map [codersdk.FeatureName ]bool {}
27
+
33
28
t .Run ("Defaults" , func (t * testing.T ) {
34
29
t .Parallel ()
35
30
db := databasefake .New ()
@@ -49,7 +44,7 @@ func TestEntitlements(t *testing.T) {
49
44
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {}),
50
45
Exp : time .Now ().Add (time .Hour ),
51
46
})
52
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [ string ] bool {} )
47
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , empty )
53
48
require .NoError (t , err )
54
49
require .True (t , entitlements .HasLicense )
55
50
require .False (t , entitlements .Trial )
@@ -75,7 +70,7 @@ func TestEntitlements(t *testing.T) {
75
70
}),
76
71
Exp : time .Now ().Add (time .Hour ),
77
72
})
78
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [ string ] bool {} )
73
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , empty )
79
74
require .NoError (t , err )
80
75
require .True (t , entitlements .HasLicense )
81
76
require .False (t , entitlements .Trial )
@@ -115,7 +110,7 @@ func TestEntitlements(t *testing.T) {
115
110
if featureName == codersdk .FeatureMultipleGitAuth {
116
111
continue
117
112
}
118
- niceName := strings . Title ( strings . ReplaceAll ( featureName , "_" , " " ) )
113
+ niceName := featureName . Humanize ( )
119
114
require .Equal (t , codersdk .EntitlementGracePeriod , entitlements .Features [featureName ].Entitlement )
120
115
require .Contains (t , entitlements .Warnings , fmt .Sprintf ("%s is enabled but your license for this feature is expired." , niceName ))
121
116
}
@@ -141,7 +136,7 @@ func TestEntitlements(t *testing.T) {
141
136
if featureName == codersdk .FeatureMultipleGitAuth {
142
137
continue
143
138
}
144
- niceName := strings . Title ( strings . ReplaceAll ( featureName , "_" , " " ) )
139
+ niceName := featureName . Humanize ( )
145
140
// Ensures features that are not entitled are properly disabled.
146
141
require .False (t , entitlements .Features [featureName ].Enabled )
147
142
require .Equal (t , codersdk .EntitlementNotEntitled , entitlements .Features [featureName ].Entitlement )
@@ -163,7 +158,7 @@ func TestEntitlements(t *testing.T) {
163
158
}),
164
159
Exp : time .Now ().Add (time .Hour ),
165
160
})
166
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [ string ] bool {} )
161
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , empty )
167
162
require .NoError (t , err )
168
163
require .True (t , entitlements .HasLicense )
169
164
require .Contains (t , entitlements .Warnings , "Your deployment has 2 active users but is only licensed for 1." )
@@ -185,7 +180,7 @@ func TestEntitlements(t *testing.T) {
185
180
}),
186
181
Exp : time .Now ().Add (time .Hour ),
187
182
})
188
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [ string ] bool {} )
183
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , empty )
189
184
require .NoError (t , err )
190
185
require .True (t , entitlements .HasLicense )
191
186
require .Empty (t , entitlements .Warnings )
@@ -208,7 +203,7 @@ func TestEntitlements(t *testing.T) {
208
203
}),
209
204
})
210
205
211
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [ string ] bool {} )
206
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , empty )
212
207
require .NoError (t , err )
213
208
require .True (t , entitlements .HasLicense )
214
209
require .False (t , entitlements .Trial )
@@ -255,7 +250,7 @@ func TestEntitlements(t *testing.T) {
255
250
AuditLog : true ,
256
251
}),
257
252
})
258
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , map [string ]bool {
253
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , map [codersdk. FeatureName ]bool {
259
254
codersdk .FeatureHighAvailability : true ,
260
255
})
261
256
require .NoError (t , err )
@@ -275,7 +270,7 @@ func TestEntitlements(t *testing.T) {
275
270
}),
276
271
Exp : time .Now ().Add (time .Hour ),
277
272
})
278
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , map [string ]bool {
273
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , map [codersdk. FeatureName ]bool {
279
274
codersdk .FeatureHighAvailability : true ,
280
275
})
281
276
require .NoError (t , err )
@@ -303,7 +298,7 @@ func TestEntitlements(t *testing.T) {
303
298
AuditLog : true ,
304
299
}),
305
300
})
306
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , map [string ]bool {
301
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , map [codersdk. FeatureName ]bool {
307
302
codersdk .FeatureMultipleGitAuth : true ,
308
303
})
309
304
require .NoError (t , err )
@@ -323,7 +318,7 @@ func TestEntitlements(t *testing.T) {
323
318
}),
324
319
Exp : time .Now ().Add (time .Hour ),
325
320
})
326
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , map [string ]bool {
321
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , map [codersdk. FeatureName ]bool {
327
322
codersdk .FeatureMultipleGitAuth : true ,
328
323
})
329
324
require .NoError (t , err )
0 commit comments