blob: c6146d467ae376e27cee119b5c1ec79906c18ac4 (
plain)
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
|
package api
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
// package utilities
func NewTestClient(ts *httptest.Server) *Client {
return &Client{
baseURL: fmt.Sprintf(ts.URL),
httpClient: ts.Client(),
}
}
func NewTestClientFromFilename(t *testing.T, filename string) (*Client, *httptest.Server) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
page, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatalf("Could not open test file : %s", err)
}
w.Write(page)
}))
return NewTestClient(ts), ts
}
// tests
func TestNewClient(t *testing.T) {
client := NewClient("test")
want := "https://test@api.sncf.com/v1"
if client.baseURL != want {
t.Fatal("Invalid new client")
}
}
|