-
Notifications
You must be signed in to change notification settings - Fork 560
/
lastfm_test.go
59 lines (47 loc) · 1.36 KB
/
lastfm_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
package lastfm
import (
"fmt"
"net/url"
"os"
"testing"
"github.com/markbates/goth"
"github.com/stretchr/testify/assert"
)
func Test_New(t *testing.T) {
t.Parallel()
a := assert.New(t)
provider := lastfmProvider()
a.Equal(provider.ClientKey, os.Getenv("LASTFM_KEY"))
a.Equal(provider.Secret, os.Getenv("LASTFM_SECRET"))
a.Equal(provider.CallbackURL, "/foo")
}
func Test_Implements_Provider(t *testing.T) {
t.Parallel()
a := assert.New(t)
a.Implements((*goth.Provider)(nil), lastfmProvider())
}
func Test_BeginAuth(t *testing.T) {
t.Parallel()
a := assert.New(t)
provider := lastfmProvider()
session, err := provider.BeginAuth("")
s := session.(*Session)
a.NoError(err)
a.Contains(s.AuthURL, "www.lastfm.com/api/auth")
a.Contains(s.AuthURL, fmt.Sprintf("api_key=%s", os.Getenv("LASTFM_KEY")))
a.Contains(s.AuthURL, fmt.Sprintf("cb=%s", url.QueryEscape("/foo")))
}
func Test_SessionFromJSON(t *testing.T) {
t.Parallel()
a := assert.New(t)
provider := lastfmProvider()
s, err := provider.UnmarshalSession(`{"AuthURL":"http://com/auth_url","AccessToken":"123456", "Login":"Quin"}`)
a.NoError(err)
session := s.(*Session)
a.Equal(session.AuthURL, "http://com/auth_url")
a.Equal(session.AccessToken, "123456")
a.Equal(session.Login, "Quin")
}
func lastfmProvider() *Provider {
return New(os.Getenv("LASTFM_KEY"), os.Getenv("LASTFM_SECRET"), "/foo")
}