-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathoptions_test.go
100 lines (89 loc) · 2.67 KB
/
options_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package oidc
import (
"testing"
"time"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/stretchr/testify/assert"
)
func TestApplyOpts(t *testing.T) {
// ApplyOpts testing is covered by other tests but we do have just more
// more test to add here.
// Let's make sure we don't panic on nil options
anonymousOpts := struct {
Names []string
}{
nil,
}
ApplyOpts(anonymousOpts, nil)
}
func Test_WithNow(t *testing.T) {
t.Parallel()
testNow := func() time.Time {
return time.Now().Add(-1 * time.Minute)
}
t.Run("tokenOptions", func(t *testing.T) {
opts := getTokenOpts(WithNow(testNow))
testOpts := tokenDefaults()
testOpts.withNowFunc = testNow
testAssertEqualFunc(t, opts.withNowFunc, testNow, "now = %p,want %p", opts.withNowFunc, testNow)
})
t.Run("reqOptions", func(t *testing.T) {
opts := getReqOpts(WithNow(testNow))
testOpts := reqDefaults()
testOpts.withNowFunc = testNow
testAssertEqualFunc(t, opts.withNowFunc, testNow, "now = %p,want %p", opts.withNowFunc, testNow)
})
}
func Test_WithAudiences(t *testing.T) {
t.Parallel()
t.Run("configOptions", func(t *testing.T) {
assert := assert.New(t)
opts := getConfigOpts(WithAudiences("alice", "bob"))
testOpts := configDefaults()
testOpts.withAudiences = []string{"alice", "bob"}
assert.Equal(opts, testOpts)
opts = getConfigOpts(WithAudiences())
testOpts = configDefaults()
testOpts.withAudiences = nil
assert.Equal(opts, testOpts)
})
t.Run("reqOptions", func(t *testing.T) {
assert := assert.New(t)
opts := getReqOpts(WithAudiences("alice", "bob"))
testOpts := reqDefaults()
testOpts.withAudiences = []string{"alice", "bob"}
assert.Equal(opts, testOpts)
opts = getReqOpts(WithAudiences())
testOpts = reqDefaults()
testOpts.withAudiences = nil
assert.Equal(opts, testOpts)
})
}
func Test_WithScopes(t *testing.T) {
t.Parallel()
t.Run("configOptions", func(t *testing.T) {
assert := assert.New(t)
opts := getConfigOpts(WithScopes("alice", "bob"))
testOpts := configDefaults()
testOpts.withScopes = []string{oidc.ScopeOpenID, "alice", "bob"}
assert.Equal(opts, testOpts)
opts = getConfigOpts(WithScopes())
testOpts = configDefaults()
testOpts.withScopes = []string{oidc.ScopeOpenID}
assert.Equal(opts, testOpts)
})
t.Run("reqOptions", func(t *testing.T) {
t.Parallel()
assert := assert.New(t)
opts := getReqOpts(WithScopes("alice", "bob"))
testOpts := reqDefaults()
testOpts.withScopes = []string{oidc.ScopeOpenID, "alice", "bob"}
assert.Equal(opts, testOpts)
opts = getReqOpts(WithScopes())
testOpts = reqDefaults()
testOpts.withScopes = nil
assert.Equal(opts, testOpts)
})
}