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

Function TestPostLicense

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

Source from the content-addressed store, hash-verified

19)
20
21func TestPostLicense(t *testing.T) {
22 t.Parallel()
23
24 t.Run("Success", func(t *testing.T) {
25 t.Parallel()
26 client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
27 respLic := coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
28 AccountType: license.AccountTypeSalesforce,
29 AccountID: "testing",
30 Features: license.Features{
31 codersdk.FeatureAuditLog: 1,
32 },
33 })
34 assert.GreaterOrEqual(t, respLic.ID, int32(0))
35 // just a couple spot checks for sanity
36 assert.Equal(t, "testing", respLic.Claims["account_id"])
37 features, err := respLic.FeaturesClaims()
38 require.NoError(t, err)
39 assert.EqualValues(t, 1, features[codersdk.FeatureAuditLog])
40 })
41
42 t.Run("InvalidDeploymentID", func(t *testing.T) {
43 t.Parallel()
44 // The generated deployment will start out with a different deployment ID.
45 client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
46 license := coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
47 DeploymentIDs: []string{uuid.NewString()},
48 })
49 _, err := client.AddLicense(context.Background(), codersdk.AddLicenseRequest{
50 License: license,
51 })
52 errResp := &codersdk.Error{}
53 require.ErrorAs(t, err, &errResp)
54 require.Equal(t, http.StatusBadRequest, errResp.StatusCode())
55 require.Contains(t, errResp.Message, "License cannot be used on this deployment!")
56 })
57
58 t.Run("InvalidAccountID", func(t *testing.T) {
59 t.Parallel()
60 // The generated deployment will start out with a different deployment ID.
61 client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
62 license := coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
63 AllowEmpty: true,
64 AccountID: "",
65 })
66 _, err := client.AddLicense(context.Background(), codersdk.AddLicenseRequest{
67 License: license,
68 })
69 errResp := &codersdk.Error{}
70 require.ErrorAs(t, err, &errResp)
71 require.Equal(t, http.StatusBadRequest, errResp.StatusCode())
72 require.Contains(t, errResp.Message, "Invalid license")
73 })
74
75 t.Run("InvalidAccountType", func(t *testing.T) {
76 t.Parallel()
77 // The generated deployment will start out with a different deployment ID.
78 client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})

Callers

nothing calls this directly

Calls 14

StatusCodeMethod · 0.95
NewFunction · 0.92
AddLicenseFunction · 0.92
GenerateLicenseFunction · 0.92
NowFunction · 0.92
FeaturesClaimsMethod · 0.80
AddLicenseMethod · 0.80
SetSessionTokenMethod · 0.80
AsMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected