forked from markbates/goth
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amazon_test.go
53 lines (43 loc) · 1.17 KB
/
amazon_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
package amazon_test
import (
"os"
"testing"
"github.com/markbates/goth"
"github.com/markbates/goth/providers/amazon"
"github.com/stretchr/testify/assert"
)
func Test_New(t *testing.T) {
t.Parallel()
a := assert.New(t)
p := provider()
a.Equal(p.ClientKey, os.Getenv("AMAZON_KEY"))
a.Equal(p.Secret, os.Getenv("AMAZON_SECRET"))
a.Equal(p.CallbackURL, "/foo")
}
func Test_Implements_Provider(t *testing.T) {
t.Parallel()
a := assert.New(t)
a.Implements((*goth.Provider)(nil), provider())
}
func Test_BeginAuth(t *testing.T) {
t.Parallel()
a := assert.New(t)
p := provider()
session, err := p.BeginAuth("test_state")
s := session.(*amazon.Session)
a.NoError(err)
a.Contains(s.AuthURL, "www.amazon.com/ap/oa")
}
func Test_SessionFromJSON(t *testing.T) {
t.Parallel()
a := assert.New(t)
p := provider()
session, err := p.UnmarshalSession(`{"AuthURL":"https://www.amazon.com/ap/oa","AccessToken":"1234567890"}`)
a.NoError(err)
s := session.(*amazon.Session)
a.Equal(s.AuthURL, "https://www.amazon.com/ap/oa")
a.Equal(s.AccessToken, "1234567890")
}
func provider() *amazon.Provider {
return amazon.New(os.Getenv("AMAZON_KEY"), os.Getenv("AMAZON_SECRET"), "/foo")
}