@@ -23,11 +23,12 @@ const (
23
23
)
24
24
25
25
type licenseTest struct {
26
- Name string
27
- License * LicensePayload
28
- Validate func (t * testing.T , eval * Evaluator )
29
- Type LicenseType
30
- NeverExpires bool
26
+ Name string
27
+ License * LicensePayload
28
+ Validate func (t * testing.T , eval * Evaluator )
29
+ Type LicenseType
30
+ NeverExpires bool
31
+ ReplicatedLicenseType * ReplicatedLicenseType
31
32
}
32
33
33
34
// roundTripFunc .
@@ -76,6 +77,12 @@ func (test *licenseTest) Run(t *testing.T) {
76
77
}
77
78
78
79
payload , err := json .Marshal (replicatedLicensePayload {
80
+ LicenseType : func () ReplicatedLicenseType {
81
+ if test .ReplicatedLicenseType == nil {
82
+ return ReplicatedLicenseTypePaid
83
+ }
84
+ return * test .ReplicatedLicenseType
85
+ }(),
79
86
ExpirationTime : func () * time.Time {
80
87
if test .License != nil {
81
88
return & test .License .ValidUntil
@@ -96,15 +103,6 @@ func (test *licenseTest) Run(t *testing.T) {
96
103
return domain
97
104
}(),
98
105
},
99
- {
100
- Field : "levelId" ,
101
- Value : func () LicenseLevel {
102
- if test .License != nil {
103
- return test .License .Level
104
- }
105
- return LevelTeam
106
- }(),
107
- },
108
106
{
109
107
Field : "seats" ,
110
108
Value : func () int {
@@ -196,9 +194,9 @@ func TestSeats(t *testing.T) {
196
194
ValidUntil : validUntil ,
197
195
},
198
196
Validate : func (t * testing.T , eval * Evaluator ) {
199
- withinLimits := eval .HasEnoughSeats (test .Probe )
197
+ withinLimits := eval .hasEnoughSeats (test .Probe )
200
198
if withinLimits != test .WithinLimits {
201
- t .Errorf ("HasEnoughSeats did not behave as expected: lic=%d probe=%d expected=%v actual=%v" , test .Licensed , test .Probe , test .WithinLimits , withinLimits )
199
+ t .Errorf ("hasEnoughSeats did not behave as expected: lic=%d probe=%d expected=%v actual=%v" , test .Licensed , test .Probe , test .WithinLimits , withinLimits )
202
200
}
203
201
},
204
202
Type : test .LicenseType ,
@@ -212,31 +210,78 @@ func TestSeats(t *testing.T) {
212
210
}
213
211
214
212
func TestFeatures (t * testing.T ) {
213
+ replicatedCommunity := ReplicatedLicenseTypeCommunity
214
+ replicatedPaid := ReplicatedLicenseTypePaid
215
+
215
216
tests := []struct {
216
- Name string
217
- DefaultLicense bool
218
- Level LicenseLevel
219
- Features []Feature
220
- LicenseType LicenseType
217
+ Name string
218
+ DefaultLicense bool
219
+ Level LicenseLevel
220
+ Features []Feature
221
+ LicenseType LicenseType
222
+ UserCount int
223
+ ReplicatedLicenseType * ReplicatedLicenseType
221
224
}{
222
- {"Gitpod: no license" , true , LicenseLevel (0 ), []Feature {FeaturePrebuild , FeatureAdminDashboard }, LicenseTypeGitpod },
223
- {"Gitpod: invalid license level" , false , LicenseLevel (666 ), []Feature {}, LicenseTypeGitpod },
224
- {"Gitpod: enterprise license" , false , LevelEnterprise , []Feature {
225
+ {"Gitpod (in seats): no license" , true , LicenseLevel (0 ), []Feature {
226
+ FeatureAdminDashboard ,
227
+ FeatureSetTimeout ,
228
+ FeatureWorkspaceSharing ,
229
+ FeatureSnapshot ,
230
+ FeaturePrebuild ,
231
+ }, LicenseTypeGitpod , 10 , nil },
232
+ {"Gitpod (in seats): invalid license level" , false , LicenseLevel (666 ), []Feature {}, LicenseTypeGitpod , seats , nil },
233
+ {"Gitpod (in seats): enterprise license" , false , LevelEnterprise , []Feature {
225
234
FeatureAdminDashboard ,
226
235
FeatureSetTimeout ,
227
236
FeatureWorkspaceSharing ,
228
237
FeatureSnapshot ,
229
238
FeaturePrebuild ,
230
- }, LicenseTypeGitpod },
239
+ }, LicenseTypeGitpod , seats , nil },
240
+
241
+ {"Gitpod (over seats): no license" , true , LicenseLevel (0 ), []Feature {
242
+ FeaturePrebuild ,
243
+ }, LicenseTypeGitpod , 11 , nil },
244
+ {"Gitpod (over seats): invalid license level" , false , LicenseLevel (666 ), []Feature {}, LicenseTypeGitpod , seats + 1 , nil },
245
+ {"Gitpod (over seats): enterprise license" , false , LevelEnterprise , []Feature {}, LicenseTypeGitpod , seats + 1 , nil },
231
246
232
- {"Replicated: invalid license level" , false , LicenseLevel (666 ), []Feature {}, LicenseTypeReplicated },
233
- {"Replicated: enterprise license" , false , LevelEnterprise , []Feature {
247
+ {"Replicated (in seats): invalid license level" , false , LicenseLevel (666 ), []Feature {
234
248
FeatureAdminDashboard ,
235
249
FeatureSetTimeout ,
236
250
FeatureWorkspaceSharing ,
237
251
FeatureSnapshot ,
238
252
FeaturePrebuild ,
239
- }, LicenseTypeReplicated },
253
+ }, LicenseTypeReplicated , seats , & replicatedPaid },
254
+ {"Replicated (in seats): enterprise license" , false , LevelEnterprise , []Feature {
255
+ FeatureAdminDashboard ,
256
+ FeatureSetTimeout ,
257
+ FeatureWorkspaceSharing ,
258
+ FeatureSnapshot ,
259
+ FeaturePrebuild ,
260
+ }, LicenseTypeReplicated , seats , & replicatedPaid },
261
+
262
+ {"Replicated (over seats - no fallback): invalid license level" , true , LicenseLevel (666 ), []Feature {
263
+ FeatureAdminDashboard ,
264
+ FeatureSetTimeout ,
265
+ FeatureWorkspaceSharing ,
266
+ FeatureSnapshot ,
267
+ FeaturePrebuild ,
268
+ }, LicenseTypeReplicated , seats + 1 , & replicatedPaid },
269
+ {"Replicated (over seats - no fallback): enterprise license" , true , LevelEnterprise , []Feature {
270
+ FeatureAdminDashboard ,
271
+ FeatureSetTimeout ,
272
+ FeatureWorkspaceSharing ,
273
+ FeatureSnapshot ,
274
+ FeaturePrebuild ,
275
+ }, LicenseTypeReplicated , seats + 1 , & replicatedPaid },
276
+
277
+ {"Replicated (over seats - fallback): invalid license level" , false , LicenseLevel (666 ), []Feature {
278
+ FeatureAdminDashboard ,
279
+ FeaturePrebuild ,
280
+ }, LicenseTypeReplicated , seats + 1 , & replicatedCommunity },
281
+ {"Replicated (over seats - fallback): enterprise license" , false , LevelEnterprise , []Feature {
282
+ FeatureAdminDashboard ,
283
+ FeaturePrebuild ,
284
+ }, LicenseTypeReplicated , seats + 1 , & replicatedCommunity },
240
285
}
241
286
242
287
for _ , test := range tests {
@@ -251,8 +296,9 @@ func TestFeatures(t *testing.T) {
251
296
lic = nil
252
297
}
253
298
lt := licenseTest {
254
- Name : test .Name ,
255
- License : lic ,
299
+ Name : test .Name ,
300
+ License : lic ,
301
+ ReplicatedLicenseType : test .ReplicatedLicenseType ,
256
302
Validate : func (t * testing.T , eval * Evaluator ) {
257
303
unavailableFeatures := featureSet {}
258
304
for f := range allowanceMap [LevelEnterprise ].Features {
@@ -261,13 +307,13 @@ func TestFeatures(t *testing.T) {
261
307
for _ , f := range test .Features {
262
308
delete (unavailableFeatures , f )
263
309
264
- if ! eval .Enabled (f ) {
310
+ if ! eval .Enabled (f , test . UserCount ) {
265
311
t .Errorf ("license does not enable %s, but should" , f )
266
312
}
267
313
}
268
314
269
315
for f := range unavailableFeatures {
270
- if eval .Enabled (f ) {
316
+ if eval .Enabled (f , test . UserCount ) {
271
317
t .Errorf ("license not enables %s, but shouldn't" , f )
272
318
}
273
319
}
0 commit comments