-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub_test.go
46 lines (38 loc) · 1002 Bytes
/
github_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
package main
import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
var (
githubTestLogin = "user1"
githubTestToken = "932928c0a4edf9878ee0257a1d8f4d06adaaffee"
testGithubServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.FormValue("access_token") == "invalid" {
io.WriteString(w, "{")
return
}
if r.FormValue("access_token") != githubTestToken {
w.WriteHeader(403)
return
}
json.NewEncoder(w).Encode(githubUser{Login: githubTestLogin})
}))
)
func init() {
*githubBase = testGithubServer.URL
}
func TestGithubErrors(t *testing.T) {
old := *githubBase
*githubBase = "https://foo.bar?"
assert.Equal(t, "", githubAuth("error"))
*githubBase = old
assert.Equal(t, "", githubAuth("invalid"))
}
func TestGithubSuccess(t *testing.T) {
assert.Equal(t, githubTestLogin, githubAuth(githubTestToken))
assert.Equal(t, githubTestLogin, githubAuth(githubTestToken))
}