-
Notifications
You must be signed in to change notification settings - Fork 7
/
context_test.go
98 lines (75 loc) · 2.44 KB
/
context_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
package linkedca
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAdminFromContext(t *testing.T) {
t.Parallel()
// nil admin; expect false
var exp *Admin
got, ok := AdminFromContext(NewContextWithAdmin(context.Background(), exp))
assert.Same(t, exp, got)
assert.False(t, ok)
// non-nil admin; expect true
exp = new(Admin)
got, ok = AdminFromContext(NewContextWithAdmin(context.Background(), exp))
assert.Same(t, exp, got)
assert.True(t, ok)
}
func TestMustAdminFromContext(t *testing.T) {
t.Parallel()
exp := new(Admin)
got := MustAdminFromContext(NewContextWithAdmin(context.Background(), exp))
assert.Same(t, exp, got)
}
func TestMustAdminFromContextPanics(t *testing.T) {
t.Parallel()
assert.Panics(t, func() { MustAdminFromContext(context.Background()) })
}
func TestProvisionerFromContext(t *testing.T) {
t.Parallel()
// nil Provisioner; expect false
var exp *Provisioner
got, ok := ProvisionerFromContext(NewContextWithProvisioner(context.Background(), exp))
assert.Same(t, exp, got)
assert.False(t, ok)
// non-nil Provisioner; expect true
exp = new(Provisioner)
got, ok = ProvisionerFromContext(NewContextWithProvisioner(context.Background(), exp))
assert.Same(t, exp, got)
assert.True(t, ok)
}
func TestMustProvisionerFromContext(t *testing.T) {
t.Parallel()
exp := new(Provisioner)
got := MustProvisionerFromContext(NewContextWithProvisioner(context.Background(), exp))
assert.Same(t, exp, got)
}
func TestMustProvisionerFromContextPanics(t *testing.T) {
t.Parallel()
assert.Panics(t, func() { MustProvisionerFromContext(context.Background()) })
}
func TestExternalAccountKeyFromContext(t *testing.T) {
t.Parallel()
// nil EABKey; expect false
var exp *EABKey
got, ok := ExternalAccountKeyFromContext(NewContextWithExternalAccountKey(context.Background(), exp))
assert.Same(t, exp, got)
assert.False(t, ok)
// non-nil EABKey; expect true
exp = new(EABKey)
got, ok = ExternalAccountKeyFromContext(NewContextWithExternalAccountKey(context.Background(), exp))
assert.Same(t, exp, got)
assert.True(t, ok)
}
func TestMustExternalAccountKeyFromContext(t *testing.T) {
t.Parallel()
exp := new(EABKey)
got := MustExternalAccountKeyFromContext(NewContextWithExternalAccountKey(context.Background(), exp))
assert.Same(t, exp, got)
}
func TestExternalAccountKeyFromContextPanics(t *testing.T) {
t.Parallel()
assert.Panics(t, func() { MustExternalAccountKeyFromContext(context.Background()) })
}