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

Function TestNewKeyPool

aibridge/keypool/keypool_test.go:15–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestNewKeyPool(t *testing.T) {
16 t.Parallel()
17
18 tests := []struct {
19 name string
20 keys []string
21 expectedKeys []string
22 expectedErr error
23 }{
24 {"nil_keys", nil, nil, keypool.ErrNoKeys},
25 {"empty_keys", []string{}, nil, keypool.ErrNoKeys},
26 {"single_key", []string{"key-0"}, []string{"key-0"}, nil},
27 {"multiple_keys", []string{"key-0", "key-1", "key-2"}, []string{"key-0", "key-1", "key-2"}, nil},
28 {"duplicate_keys", []string{"key-0", "key-1", "key-0"}, nil, keypool.ErrDuplicateKey},
29 }
30
31 for _, tc := range tests {
32 t.Run(tc.name, func(t *testing.T) {
33 t.Parallel()
34 pool, err := keypool.New(tc.keys, quartz.NewMock(t))
35 if tc.expectedErr != nil {
36 require.ErrorIs(t, err, tc.expectedErr)
37 return
38 }
39 require.NoError(t, err)
40 require.NotNil(t, pool)
41
42 // Verify all keys are returned in order and valid.
43 walker := pool.Walker()
44 for _, expected := range tc.expectedKeys {
45 key, keyPoolErr := walker.Next()
46 require.Nil(t, keyPoolErr)
47 assert.Equal(t, expected, key.Value())
48 assert.Equal(t, keypool.KeyStateValid, key.State())
49 }
50
51 // No more keys available.
52 _, keyPoolErr := walker.Next()
53 require.Equal(t, &keypool.Error{Kind: keypool.ErrorKindRateLimited}, keyPoolErr, "expected rate-limited exhaustion: walker returned all valid keys, none marked permanent")
54 })
55 }
56}
57
58func TestState(t *testing.T) {
59 t.Parallel()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
WalkerMethod · 0.80
RunMethod · 0.65
NextMethod · 0.65
EqualMethod · 0.45
ValueMethod · 0.45
StateMethod · 0.45

Tested by

no test coverage detected