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

Function TestAPIKey_SetDefault

coderd/apikey_test.go:493–515  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

491}
492
493func TestAPIKey_SetDefault(t *testing.T) {
494 t.Parallel()
495
496 db, pubsub := dbtestutil.NewDB(t)
497 dc := coderdtest.DeploymentValues(t)
498 dc.Sessions.DefaultTokenDuration = serpent.Duration(time.Hour * 12)
499 client := coderdtest.New(t, &coderdtest.Options{
500 Database: db,
501 Pubsub: pubsub,
502 DeploymentValues: dc,
503 })
504 owner := coderdtest.CreateFirstUser(t, client)
505
506 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
507 defer cancel()
508
509 token, err := client.CreateAPIKey(ctx, owner.UserID.String())
510 require.NoError(t, err)
511 split := strings.Split(token.Key, "-")
512 apiKey1, err := db.GetAPIKeyByID(ctx, split[0])
513 require.NoError(t, err)
514 require.EqualValues(t, dc.Sessions.DefaultTokenDuration.Value().Seconds(), apiKey1.LifetimeSeconds)
515}
516
517func TestAPIKey_PrebuildsNotAllowed(t *testing.T) {
518 t.Parallel()

Callers

nothing calls this directly

Calls 9

NewDBFunction · 0.92
DeploymentValuesFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
DurationMethod · 0.80
CreateAPIKeyMethod · 0.80
GetAPIKeyByIDMethod · 0.65
StringMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected