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

Function TestState

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

Source from the content-addressed store, hash-verified

56}
57
58func TestState(t *testing.T) {
59 t.Parallel()
60
61 tests := []struct {
62 name string
63 setup func(t *testing.T, pool *keypool.Pool, clk *quartz.Mock) *keypool.Key
64 expectedState keypool.KeyState
65 }{
66 {
67 // Fresh key is valid.
68 name: "fresh_key_is_valid",
69 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
70 key, keyPoolErr := pool.Walker().Next()
71 require.Nil(t, keyPoolErr)
72 return key
73 },
74 expectedState: keypool.KeyStateValid,
75 },
76 {
77 // Active cooldown makes the key temporary.
78 name: "active_cooldown_is_temporary",
79 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
80 key, keyPoolErr := pool.Walker().Next()
81 require.Nil(t, keyPoolErr)
82 key.MarkTemporary(60 * time.Second)
83 return key
84 },
85 expectedState: keypool.KeyStateTemporary,
86 },
87 {
88 // Expired cooldown returns the key to valid.
89 name: "expired_cooldown_is_valid",
90 setup: func(t *testing.T, pool *keypool.Pool, clk *quartz.Mock) *keypool.Key {
91 key, keyPoolErr := pool.Walker().Next()
92 require.Nil(t, keyPoolErr)
93 key.MarkTemporary(30 * time.Second)
94 clk.Advance(35 * time.Second)
95 return key
96 },
97 expectedState: keypool.KeyStateValid,
98 },
99 {
100 // Permanent key is permanent.
101 name: "permanent_key",
102 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
103 key, keyPoolErr := pool.Walker().Next()
104 require.Nil(t, keyPoolErr)
105 key.MarkPermanent()
106 return key
107 },
108 expectedState: keypool.KeyStatePermanent,
109 },
110 {
111 // Permanent takes precedence over active cooldown.
112 name: "permanent_with_cooldown_is_permanent",
113 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
114 key, keyPoolErr := pool.Walker().Next()
115 require.Nil(t, keyPoolErr)

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
WalkerMethod · 0.80
MarkTemporaryMethod · 0.80
MarkPermanentMethod · 0.80
NextMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.45
StateMethod · 0.45

Tested by

no test coverage detected