-
Notifications
You must be signed in to change notification settings - Fork 10
/
account_test.go
executable file
·65 lines (53 loc) · 1.77 KB
/
account_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
package imgur
import (
"net/http"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestVerifyEmptyInputParams(t *testing.T) {
client, err := NewClient(http.DefaultClient, "testing", "")
require.NoError(t, err)
_, err = client.RefreshAccessToken("", "secret")
require.Error(t, err)
_, err = client.RefreshAccessToken("12345", "")
require.Error(t, err)
}
func TestStubbedClientAuthorization(t *testing.T) {
responseBody := `
{
"access_token": "argus",
"expires_in": 315360000,
"token_type": "bearer",
"scope": null,
"refresh_token": "red bull",
"account_id": 111111111,
"account_username": "Locker"
}`
httpC, server := testHTTPClientJSON(responseBody)
defer server.Close()
client, err := NewClient(httpC, "testing", "")
require.NoError(t, err)
newRefreshToken, err := client.RefreshAccessToken("12345", "to secret")
require.NoError(t, err)
require.Equal(t, "red bull", newRefreshToken)
require.Equal(t, "argus", client.imgurAccount.accessToken)
}
func TestRealClientAuthorization(t *testing.T) {
clientID := os.Getenv("IMGURCLIENTID")
refreshToken := os.Getenv("IMGURCLIENTREFRESHTOKEN")
clientSecret := os.Getenv("IMGURCLIENTSECRET")
if clientID == "" || refreshToken == "" || clientSecret == "" {
t.Skipf("Environment variables not set. ID: %t , refresh: %t , secret: %t",
clientID == "", refreshToken == "", clientSecret == "")
}
client, err := NewClient(&http.Client{}, clientID, "")
require.NoError(t, err)
refreshToken, err = client.RefreshAccessToken(refreshToken, clientSecret)
require.NoError(t, err)
client.imgurAccount.accessToken = "access token"
// update refresh token
err = os.Setenv("IMGURCLIENTREFRESHTOKEN", refreshToken)
require.NoError(t, err)
require.NotEqual(t, "access token", client.imgurAccount.accessToken)
}