This repository has been archived by the owner on May 6, 2021. It is now read-only.
forked from yamadapc/gomniauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_list_test.go
103 lines (67 loc) · 2.07 KB
/
provider_list_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
101
102
103
package gomniauth
import (
"github.com/toggl/gomniauth/common"
"github.com/toggl/gomniauth/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
)
func TestInterface(t *testing.T) {
var list common.ProviderList
list = new(ProviderList)
assert.NotNil(t, list)
}
func TestWithProviders(t *testing.T) {
common.SetSecurityKey("ABC123")
prov1 := new(test.TestProvider)
prov2 := new(test.TestProvider)
list := WithProviders(prov1, prov2)
if assert.NotNil(t, list) {
if assert.Equal(t, 2, len(list.providers)) {
assert.Equal(t, prov1, list.providers[0])
assert.Equal(t, prov2, list.providers[1])
}
// make sure the SharedProviderList was assigned too
assert.Equal(t, SharedProviderList, list)
}
}
func TestProviders(t *testing.T) {
prov1 := new(test.TestProvider)
prov2 := new(test.TestProvider)
list := WithProviders(prov1, prov2)
if assert.Equal(t, 2, len(list.Providers())) {
assert.Equal(t, prov1, list.Providers()[0])
assert.Equal(t, prov2, list.Providers()[1])
}
}
func TestProviderListProvider(t *testing.T) {
prov1 := new(test.TestProvider)
prov2 := new(test.TestProvider)
prov1.On("Name").Return("prov1")
prov2.On("Name").Return("prov2")
// build a list
list := WithProviders(prov1, prov2)
returnedProv, err := list.Provider("prov1")
if assert.NoError(t, err) {
assert.Equal(t, returnedProv, prov1)
}
// check nonsense name
returnedProv, err = list.Provider("no such provider")
if assert.Nil(t, returnedProv) {
assert.IsType(t, &common.MissingProviderError{}, err, "MissingProviderError expected")
}
mock.AssertExpectationsForObjects(t, prov1.Mock, prov2.Mock)
}
func TestAdd(t *testing.T) {
prov1 := new(test.TestProvider)
prov2 := new(test.TestProvider)
prov3 := new(test.TestProvider)
// build a list
list := WithProviders(prov1, prov2)
if assert.Equal(t, 2, len(list.providers)) {
// add prov3
assert.Equal(t, list, list.Add(prov3), "Add should chain")
assert.Equal(t, 3, len(list.providers), "Add should add the provider")
assert.Equal(t, prov3, list.providers[2])
}
}