forked from Hakkin/twitchpipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess_test.go
42 lines (36 loc) · 873 Bytes
/
access_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
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"testing"
)
func TestGetAccessToken(t *testing.T) {
testUsername := "testing"
token := &accessToken{
Token: "token",
Sig: "sig",
}
client := NewTestClient(func(req *http.Request) *http.Response {
aURL, err := url.Parse(fmt.Sprintf(accessURL, testUsername))
ok(t, err)
query := aURL.Query()
query.Set("player_type", "embed")
aURL.RawQuery = query.Encode()
equals(t, aURL.String(), req.URL.String())
equals(t, clientID, req.Header.Get("Client-ID"))
var jsonBuf bytes.Buffer
ok(t, json.NewEncoder(&jsonBuf).Encode(token))
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(&jsonBuf),
Header: make(http.Header),
}
})
testToken, err := getAcessToken(client, testUsername)
ok(t, err)
equals(t, token, testToken)
}