MCPcopy Index your code
hub / github.com/coder/coder / TestDeleteLicense

Function TestDeleteLicense

enterprise/coderd/licenses_test.go:244–305  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

242}
243
244func TestDeleteLicense(t *testing.T) {
245 t.Parallel()
246 t.Run("Empty", func(t *testing.T) {
247 t.Parallel()
248 client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
249 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
250 defer cancel()
251
252 err := client.DeleteLicense(ctx, 1)
253 errResp := &codersdk.Error{}
254 if xerrors.As(err, &errResp) {
255 assert.Equal(t, 404, errResp.StatusCode())
256 } else {
257 t.Error("expected to get error status 404")
258 }
259 })
260
261 t.Run("BadID", func(t *testing.T) {
262 t.Parallel()
263 client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
264 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
265 defer cancel()
266
267 //nolint:gocritic // RBAC is irrelevant here.
268 resp, err := client.Request(ctx, http.MethodDelete, "/api/v2/licenses/drivers", nil)
269 require.NoError(t, err)
270 assert.Equal(t, http.StatusNotFound, resp.StatusCode)
271 require.NoError(t, resp.Body.Close())
272 })
273
274 t.Run("Success", func(t *testing.T) {
275 t.Parallel()
276 client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
277 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
278 defer cancel()
279
280 coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
281 AccountID: "testing",
282 Features: license.Features{
283 codersdk.FeatureAuditLog: 1,
284 },
285 })
286 coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
287 AccountID: "testing2",
288 Features: license.Features{
289 codersdk.FeatureAuditLog: 1,
290 codersdk.FeatureUserLimit: 200,
291 },
292 })
293
294 licenses, err := client.Licenses(ctx)
295 require.NoError(t, err)
296 assert.Len(t, licenses, 2)
297 for _, l := range licenses {
298 err = client.DeleteLicense(ctx, l.ID)
299 require.NoError(t, err)
300 }
301 licenses, err = client.Licenses(ctx)

Callers

nothing calls this directly

Calls 12

StatusCodeMethod · 0.95
NewFunction · 0.92
AddLicenseFunction · 0.92
AsMethod · 0.80
LicensesMethod · 0.80
RunMethod · 0.65
DeleteLicenseMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45
ErrorMethod · 0.45
RequestMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected