forked from whitepages/go-stingray
-
Notifications
You must be signed in to change notification settings - Fork 7
/
stingray_test.go
59 lines (46 loc) · 1.33 KB
/
stingray_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 stingray
import (
"net/http"
"net/http/httptest"
"testing"
)
var (
// mux is the HTTP request multiplexer used with the test server.
mux *http.ServeMux
// client is the GitHub client being tested.
client *Client
// server is a test HTTP server used to provide mock API responses.
server *httptest.Server
)
// setup sets up a test HTTP server along with a github.Client that is
// configured to talk to that test server. Tests should register handlers on
// mux which provide mock responses for the API method being tested.
func setup() {
// test server
mux = http.NewServeMux()
server = httptest.NewServer(mux)
// Stingray client configured to use test server
client = NewClient(nil, server.URL, "username", "password")
}
// teardown closes the test HTTP server.
func teardown() {
server.Close()
}
func TestNewClient(t *testing.T) {
url := "http://localhost:9070/"
username := "username"
password := "password"
c := NewClient(nil, url, username, password)
if c.Client == nil {
t.Errorf("NewClient Client is nil")
}
if c.BaseURL.String() != url {
t.Errorf("NewClient URL = %v, want %v", c.BaseURL.String(), url)
}
if c.Username != username {
t.Errorf("NewClient USERNAME = %v, want %v", c.Username, username)
}
if c.Password != password {
t.Errorf("NewClient PASSWORD = %v, want %v", c.Password, password)
}
}