aboutsummaryrefslogtreecommitdiff
path: root/pkg/navitia_api_client/client_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/navitia_api_client/client_test.go')
-rw-r--r--pkg/navitia_api_client/client_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/pkg/navitia_api_client/client_test.go b/pkg/navitia_api_client/client_test.go
new file mode 100644
index 0000000..332b222
--- /dev/null
+++ b/pkg/navitia_api_client/client_test.go
@@ -0,0 +1,38 @@
+package navitia_api_client
+
+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(),
+ cache: make(map[string]cachedResult),
+ }
+}
+
+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")
+ }
+}