-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathshortcuts_test.go
60 lines (42 loc) · 1.28 KB
/
shortcuts_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
package gomniauth
import (
"github.com/stretchr/gomniauth/common"
"github.com/stretchr/gomniauth/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
)
func TestNewState(t *testing.T) {
s := NewState("one", 1, "two", 2)
if assert.NotNil(t, s) {
assert.Equal(t, 1, s.Get("one").Data())
assert.Equal(t, 2, s.Get("two").Data())
}
}
func TestStateFromParam(t *testing.T) {
state := NewState("name", "Mat", "age", 30)
hash, _ := state.SignedBase64(GetSecurityKey())
s, err := StateFromParam(hash)
if assert.NotNil(t, s) && assert.NoError(t, err) {
assert.Equal(t, "Mat", s.Get("name").Data())
assert.Equal(t, 30, s.Get("age").Data())
}
}
func TestProvider(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 = Provider("no such provider")
if assert.Nil(t, returnedProv) {
assert.IsType(t, &common.MissingProviderError{}, err, "MissingProviderError expected")
}
mock.AssertExpectationsForObjects(t, prov1.Mock, prov2.Mock)
}