(t *testing.T)
| 217 | } |
| 218 | |
| 219 | func TestMarkPermanent(t *testing.T) { |
| 220 | t.Parallel() |
| 221 | |
| 222 | tests := []struct { |
| 223 | name string |
| 224 | setup func(t *testing.T, pool *keypool.Pool) *keypool.Key |
| 225 | expectedState keypool.KeyState |
| 226 | expectedTransition bool |
| 227 | }{ |
| 228 | { |
| 229 | // valid -> permanent: key becomes permanently unavailable. |
| 230 | name: "valid_to_permanent", |
| 231 | setup: func(t *testing.T, pool *keypool.Pool) *keypool.Key { |
| 232 | key, keyPoolErr := pool.Walker().Next() |
| 233 | require.Nil(t, keyPoolErr) |
| 234 | return key |
| 235 | }, |
| 236 | expectedState: keypool.KeyStatePermanent, |
| 237 | expectedTransition: true, |
| 238 | }, |
| 239 | { |
| 240 | // temporary -> permanent: escalation from rate limit |
| 241 | // to auth failure. |
| 242 | name: "temporary_to_permanent", |
| 243 | setup: func(t *testing.T, pool *keypool.Pool) *keypool.Key { |
| 244 | key, keyPoolErr := pool.Walker().Next() |
| 245 | require.Nil(t, keyPoolErr) |
| 246 | key.MarkTemporary(60 * time.Second) |
| 247 | return key |
| 248 | }, |
| 249 | expectedState: keypool.KeyStatePermanent, |
| 250 | expectedTransition: true, |
| 251 | }, |
| 252 | { |
| 253 | // permanent -> permanent: no-op, already permanent. |
| 254 | name: "permanent_to_permanent", |
| 255 | setup: func(t *testing.T, pool *keypool.Pool) *keypool.Key { |
| 256 | key, keyPoolErr := pool.Walker().Next() |
| 257 | require.Nil(t, keyPoolErr) |
| 258 | key.MarkPermanent() |
| 259 | return key |
| 260 | }, |
| 261 | expectedState: keypool.KeyStatePermanent, |
| 262 | expectedTransition: false, |
| 263 | }, |
| 264 | } |
| 265 | |
| 266 | for _, tc := range tests { |
| 267 | t.Run(tc.name, func(t *testing.T) { |
| 268 | t.Parallel() |
| 269 | clk := quartz.NewMock(t) |
| 270 | pool, err := keypool.New([]string{"key-0", "key-1"}, clk) |
| 271 | require.NoError(t, err) |
| 272 | |
| 273 | key := tc.setup(t, pool) |
| 274 | transition := key.MarkPermanent() |
| 275 | |
| 276 | assert.Equal(t, tc.expectedState, key.State()) |
nothing calls this directly
no test coverage detected