@@ -23,11 +23,12 @@ const (
2323)
2424
2525type 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
3132}
3233
3334// roundTripFunc .
@@ -76,6 +77,12 @@ func (test *licenseTest) Run(t *testing.T) {
7677 }
7778
7879 payload , err := json .Marshal (replicatedLicensePayload {
80+ LicenseType : func () ReplicatedLicenseType {
81+ if test .ReplicatedLicenseType == nil {
82+ return ReplicatedLicenseTypePaid
83+ }
84+ return * test .ReplicatedLicenseType
85+ }(),
7986 ExpirationTime : func () * time.Time {
8087 if test .License != nil {
8188 return & test .License .ValidUntil
@@ -96,15 +103,6 @@ func (test *licenseTest) Run(t *testing.T) {
96103 return domain
97104 }(),
98105 },
99- {
100- Field : "levelId" ,
101- Value : func () LicenseLevel {
102- if test .License != nil {
103- return test .License .Level
104- }
105- return LevelTeam
106- }(),
107- },
108106 {
109107 Field : "seats" ,
110108 Value : func () int {
@@ -196,9 +194,9 @@ func TestSeats(t *testing.T) {
196194 ValidUntil : validUntil ,
197195 },
198196 Validate : func (t * testing.T , eval * Evaluator ) {
199- withinLimits := eval .HasEnoughSeats (test .Probe )
197+ withinLimits := eval .hasEnoughSeats (test .Probe )
200198 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 )
202200 }
203201 },
204202 Type : test .LicenseType ,
@@ -212,31 +210,78 @@ func TestSeats(t *testing.T) {
212210}
213211
214212func TestFeatures (t * testing.T ) {
213+ replicatedCommunity := ReplicatedLicenseTypeCommunity
214+ replicatedPaid := ReplicatedLicenseTypePaid
215+
215216 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
221224 }{
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 {
225234 FeatureAdminDashboard ,
226235 FeatureSetTimeout ,
227236 FeatureWorkspaceSharing ,
228237 FeatureSnapshot ,
229238 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 },
231246
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 {
234248 FeatureAdminDashboard ,
235249 FeatureSetTimeout ,
236250 FeatureWorkspaceSharing ,
237251 FeatureSnapshot ,
238252 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 },
240285 }
241286
242287 for _ , test := range tests {
@@ -251,8 +296,9 @@ func TestFeatures(t *testing.T) {
251296 lic = nil
252297 }
253298 lt := licenseTest {
254- Name : test .Name ,
255- License : lic ,
299+ Name : test .Name ,
300+ License : lic ,
301+ ReplicatedLicenseType : test .ReplicatedLicenseType ,
256302 Validate : func (t * testing.T , eval * Evaluator ) {
257303 unavailableFeatures := featureSet {}
258304 for f := range allowanceMap [LevelEnterprise ].Features {
@@ -261,13 +307,13 @@ func TestFeatures(t *testing.T) {
261307 for _ , f := range test .Features {
262308 delete (unavailableFeatures , f )
263309
264- if ! eval .Enabled (f ) {
310+ if ! eval .Enabled (f , test . UserCount ) {
265311 t .Errorf ("license does not enable %s, but should" , f )
266312 }
267313 }
268314
269315 for f := range unavailableFeatures {
270- if eval .Enabled (f ) {
316+ if eval .Enabled (f , test . UserCount ) {
271317 t .Errorf ("license not enables %s, but shouldn't" , f )
272318 }
273319 }
0 commit comments