From bb78fe4cbac510b54d49f41efbdb35ffe7175299 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 18 Mar 2021 20:12:43 +0100 Subject: Added api module with departures feature --- api/client_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 api/client_test.go (limited to 'api/client_test.go') diff --git a/api/client_test.go b/api/client_test.go new file mode 100644 index 0000000..c6146d4 --- /dev/null +++ b/api/client_test.go @@ -0,0 +1,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") + } +} -- cgit v1.2.3