forked from lestrrat-go/jwx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_test.go
72 lines (59 loc) · 1.32 KB
/
set_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package jwk_test
import (
"testing"
"github.com/lestrrat-go/jwx/internal/jwxtest"
"github.com/lestrrat-go/jwx/jwk"
"github.com/stretchr/testify/assert"
)
func TestSet(t *testing.T) {
set := jwk.NewSet()
keygens := []func() (jwk.Key, error){
jwxtest.GenerateRsaJwk,
jwxtest.GenerateEcdsaJwk,
jwxtest.GenerateSymmetricJwk,
}
//nolint:prealloc
var keys []jwk.Key
for _, gen := range keygens {
k, err := gen()
if !assert.NoError(t, err, `key generation should succeed`) {
return
}
if !assert.True(t, set.Add(k), `set.Add should succeed`) {
return
}
keys = append(keys, k)
}
if !assert.Equal(t, set.Len(), 3, `set.Len should be 3`) {
return
}
for i, k := range keys {
if !assert.Equal(t, i, set.Index(k), `set.Index should return %d`, i) {
return
}
}
for _, k := range keys {
if !assert.True(t, set.Remove(k), `set.Remove should succeed`) {
return
}
}
if !assert.Equal(t, set.Len(), 0, `set.Len should be 0`) {
return
}
for _, gen := range keygens {
k, err := gen()
if !assert.NoError(t, err, `key generation should succeed`) {
return
}
if !assert.True(t, set.Add(k), `set.Add should succeed`) {
return
}
}
if !assert.Equal(t, set.Len(), 3, `set.Len should be 3`) {
return
}
set.Clear()
if !assert.Equal(t, set.Len(), 0, `set.Len should be 0`) {
return
}
}