aboutsummaryrefslogtreecommitdiff
path: root/pkg/navitia_api_client/client_test.go
blob: 009712d72dce2d7f8edf1047ef80e6eb158b97ac (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
package navitia_api_client

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"testing"
)

// package utilities
func newTestClient(ts *httptest.Server) *NavitiaClient {
	return &NavitiaClient{
		baseURL:    fmt.Sprintf(ts.URL),
		httpClient: ts.Client(),
		cache:      make(map[string]cachedResult),
	}
}

func newTestClientFromFilename(t *testing.T, filename string) (*NavitiaClient, *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
}