forked from MicahParks/jwkset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
45 lines (34 loc) · 1.07 KB
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package jwkset_test
import (
"context"
"errors"
"testing"
"time"
"github.com/MicahParks/jwkset"
)
var (
errStorage = errors.New("storage error")
)
type storageError[CustomKeyMeta any] struct{}
func (s storageError[CustomKeyMeta]) DeleteKey(ctx context.Context, keyID string) (ok bool, err error) {
return false, errStorage
}
func (s storageError[CustomKeyMeta]) ReadKey(ctx context.Context, keyID string) (jwkset.KeyWithMeta[CustomKeyMeta], error) {
return jwkset.KeyWithMeta[CustomKeyMeta]{}, errStorage
}
func (s storageError[CustomKeyMeta]) SnapshotKeys(ctx context.Context) ([]jwkset.KeyWithMeta[CustomKeyMeta], error) {
return nil, errStorage
}
func (s storageError[CustomKeyMeta]) WriteKey(ctx context.Context, meta jwkset.KeyWithMeta[CustomKeyMeta]) error {
return errStorage
}
func TestStorageError(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
jwks := jwkset.NewMemory[any]()
jwks.Store = storageError[any]{}
_, err := jwks.JSONPublic(ctx)
if err == nil {
t.Fatalf("Expected error, but got none.")
}
}