forked from hashicorp/cap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid_test.go
54 lines (50 loc) · 1.17 KB
/
id_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
package oidc
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewID(t *testing.T) {
t.Parallel()
tests := []struct {
name string
opt []Option
wantErr bool
wantPrefix string
wantLen int
}{
{
name: "no-prefix",
wantLen: DefaultIDLength,
},
{
name: "with-prefix",
opt: []Option{WithPrefix("alice")},
wantPrefix: "alice",
wantLen: DefaultIDLength + len("alice_"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, err := NewID(tt.opt...)
if tt.wantErr {
require.Error(err)
return
}
require.NoError(err)
if tt.wantPrefix != "" {
assert.Containsf(got, tt.wantPrefix, "NewID() = %v and wanted prefix %s", got, tt.wantPrefix)
}
assert.Equalf(tt.wantLen, len(got), "NewID() = %v, with len of %d and wanted len of %v", got, len(got), tt.wantLen)
})
}
}
func Test_WithPrefix(t *testing.T) {
t.Parallel()
assert := assert.New(t)
opts := getIDOpts(WithPrefix("alice"))
testOpts := idDefaults()
testOpts.withPrefix = "alice"
assert.Equal(opts, testOpts)
}