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

Function TestGenerate

coderd/apikey/apikey_test.go:17–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestGenerate(t *testing.T) {
18 t.Parallel()
19
20 type testcase struct {
21 name string
22 params apikey.CreateParams
23 fail bool
24 }
25
26 cases := []testcase{
27 {
28 name: "OK",
29 params: apikey.CreateParams{
30 UserID: uuid.New(),
31 LoginType: database.LoginTypeOIDC,
32 DefaultLifetime: time.Duration(0),
33 ExpiresAt: time.Now().Add(time.Hour),
34 LifetimeSeconds: int64(time.Hour.Seconds()),
35 TokenName: "hello",
36 RemoteAddr: "1.2.3.4",
37 Scope: database.ApiKeyScopeCoderApplicationConnect,
38 },
39 },
40 {
41 name: "InvalidScope",
42 params: apikey.CreateParams{
43 UserID: uuid.New(),
44 LoginType: database.LoginTypeOIDC,
45 DefaultLifetime: time.Duration(0),
46 ExpiresAt: time.Now().Add(time.Hour),
47 LifetimeSeconds: int64(time.Hour.Seconds()),
48 TokenName: "hello",
49 RemoteAddr: "1.2.3.4",
50 Scope: database.APIKeyScope("test"),
51 },
52 fail: true,
53 },
54 {
55 name: "DeploymentSessionDuration",
56 params: apikey.CreateParams{
57 UserID: uuid.New(),
58 LoginType: database.LoginTypeOIDC,
59 DefaultLifetime: time.Hour,
60 LifetimeSeconds: 0,
61 ExpiresAt: time.Time{},
62 TokenName: "hello",
63 RemoteAddr: "1.2.3.4",
64 Scope: database.ApiKeyScopeCoderApplicationConnect,
65 },
66 },
67 {
68 name: "LifetimeSeconds",
69 params: apikey.CreateParams{
70 UserID: uuid.New(),
71 LoginType: database.LoginTypeOIDC,
72 DefaultLifetime: time.Duration(0),
73 LifetimeSeconds: int64(time.Hour.Seconds()),
74 ExpiresAt: time.Time{},

Callers

nothing calls this directly

Calls 15

APIKeyScopeTypeAlias · 0.92
GenerateFunction · 0.92
ValidateHashFunction · 0.92
NowFunction · 0.92
DurationMethod · 0.80
NotEmptyMethod · 0.80
NewMethod · 0.65
AddMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected