Skip to content

Commit 5876b19

Browse files
author
Simon Emms
committed
update tests to make it all work
1 parent 73d4261 commit 5876b19

File tree

1 file changed

+8
-78
lines changed

1 file changed

+8
-78
lines changed

components/licensor/ee/pkg/licensor/licensor_test.go

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -140,103 +140,33 @@ func (test *licenseTest) Run(t *testing.T) {
140140
})
141141
}
142142

143-
func TestSeats(t *testing.T) {
144-
tests := []struct {
145-
Name string
146-
Licensed int
147-
Probe int
148-
WithinLimits bool
149-
DefaultLicense bool
150-
InvalidLicense bool
151-
LicenseType LicenseType
152-
NeverExpires bool
153-
}{
154-
{"Gitpod: unlimited seats", 0, 1000, true, false, false, LicenseTypeGitpod, false},
155-
{"Gitpod: within limited seats", 50, 40, true, false, false, LicenseTypeGitpod, false},
156-
{"Gitpod: within limited seats (edge)", 50, 50, true, false, false, LicenseTypeGitpod, false},
157-
{"Gitpod: beyond limited seats", 50, 150, false, false, false, LicenseTypeGitpod, false},
158-
{"Gitpod: beyond limited seats (edge)", 50, 51, false, false, false, LicenseTypeGitpod, false},
159-
{"Gitpod: invalid license", 50, 50, false, false, true, LicenseTypeGitpod, false},
160-
{"Gitpod: within default license seats", 0, 7, true, true, false, LicenseTypeGitpod, false},
161-
{"Gitpod: within default license seats (edge)", 0, 10, true, true, false, LicenseTypeGitpod, false},
162-
{"Gitpod: beyond default license seats", 0, 11, false, true, false, LicenseTypeGitpod, false},
163-
164-
// correctly missing the default license tests as Replicated always has a license
165-
{"Replicated: unlimited seats", 0, 1000, true, false, false, LicenseTypeReplicated, false},
166-
{"Replicated: within limited seats", 50, 40, true, false, false, LicenseTypeReplicated, false},
167-
{"Replicated: within limited seats (edge)", 50, 50, true, false, false, LicenseTypeReplicated, false},
168-
{"Replicated: beyond limited seats", 50, 150, false, false, false, LicenseTypeReplicated, false},
169-
{"Replicated: beyond limited seats (edge)", 50, 51, false, false, false, LicenseTypeReplicated, false},
170-
{"Replicated: invalid license", 50, 50, false, false, true, LicenseTypeReplicated, false},
171-
{"Replicated: beyond default license seats", 0, 11, false, true, false, LicenseTypeReplicated, false},
172-
173-
{"Replicated: unlimited seats", 0, 1000, true, false, false, LicenseTypeReplicated, true},
174-
{"Replicated: within limited seats", 50, 40, true, false, false, LicenseTypeReplicated, true},
175-
{"Replicated: within limited seats (edge)", 50, 50, true, false, false, LicenseTypeReplicated, true},
176-
{"Replicated: beyond limited seats", 50, 150, false, false, false, LicenseTypeReplicated, true},
177-
{"Replicated: beyond limited seats (edge)", 50, 51, false, false, false, LicenseTypeReplicated, true},
178-
{"Replicated: invalid license", 50, 50, false, false, true, LicenseTypeReplicated, true},
179-
{"Replicated: beyond default license seats", 0, 11, false, true, false, LicenseTypeReplicated, true},
180-
{"Replicated: invalid license within default seats", 50, 5, true, false, true, LicenseTypeReplicated, false},
181-
}
182-
183-
for _, test := range tests {
184-
validUntil := time.Now().Add(6 * time.Hour)
185-
if test.InvalidLicense {
186-
validUntil = time.Now().Add(-6 * time.Hour)
187-
}
188-
189-
lt := licenseTest{
190-
Name: test.Name,
191-
License: &LicensePayload{
192-
ID: someID,
193-
Domain: domain,
194-
Level: LevelTeam,
195-
Seats: test.Licensed,
196-
ValidUntil: validUntil,
197-
},
198-
Validate: func(t *testing.T, eval *Evaluator) {
199-
withinLimits := eval.HasEnoughSeats(test.Probe)
200-
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)
202-
}
203-
},
204-
Type: test.LicenseType,
205-
NeverExpires: test.NeverExpires,
206-
}
207-
if test.DefaultLicense {
208-
lt.License = nil
209-
}
210-
lt.Run(t)
211-
}
212-
}
213-
214143
func TestFeatures(t *testing.T) {
215144
tests := []struct {
216145
Name string
217146
DefaultLicense bool
218147
Level LicenseLevel
219148
Features []Feature
220149
LicenseType LicenseType
150+
Seats int
221151
}{
222-
{"Gitpod: no license", true, LicenseLevel(0), []Feature{FeaturePrebuild, FeatureAdminDashboard}, LicenseTypeGitpod},
223-
{"Gitpod: invalid license level", false, LicenseLevel(666), []Feature{}, LicenseTypeGitpod},
152+
{"Gitpod: no license", true, LicenseLevel(0), []Feature{FeaturePrebuild, FeatureAdminDashboard}, LicenseTypeGitpod, 1},
153+
{"Gitpod: invalid license level", false, LicenseLevel(666), []Feature{}, LicenseTypeGitpod, 1},
224154
{"Gitpod: enterprise license", false, LevelEnterprise, []Feature{
225155
FeatureAdminDashboard,
226156
FeatureSetTimeout,
227157
FeatureWorkspaceSharing,
228158
FeatureSnapshot,
229159
FeaturePrebuild,
230-
}, LicenseTypeGitpod},
160+
}, LicenseTypeGitpod, 1},
231161

232-
{"Replicated: invalid license level", false, LicenseLevel(666), []Feature{}, LicenseTypeReplicated},
162+
{"Replicated: invalid license level", false, LicenseLevel(666), []Feature{}, LicenseTypeReplicated, 1},
233163
{"Replicated: enterprise license", false, LevelEnterprise, []Feature{
234164
FeatureAdminDashboard,
235165
FeatureSetTimeout,
236166
FeatureWorkspaceSharing,
237167
FeatureSnapshot,
238168
FeaturePrebuild,
239-
}, LicenseTypeReplicated},
169+
}, LicenseTypeReplicated, 1},
240170
}
241171

242172
for _, test := range tests {
@@ -261,13 +191,13 @@ func TestFeatures(t *testing.T) {
261191
for _, f := range test.Features {
262192
delete(unavailableFeatures, f)
263193

264-
if !eval.Enabled(f) {
194+
if !eval.Enabled(f, test.Seats) {
265195
t.Errorf("license does not enable %s, but should", f)
266196
}
267197
}
268198

269199
for f := range unavailableFeatures {
270-
if eval.Enabled(f) {
200+
if eval.Enabled(f, test.Seats) {
271201
t.Errorf("license not enables %s, but shouldn't", f)
272202
}
273203
}

0 commit comments

Comments
 (0)