From dbb4167a49343defa8be01921c3943d7eeb8b9dd Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 29 Mar 2021 00:07:03 +0200 Subject: Renamed the api folder to something more specific --- navitia_api_client/departures_test.go | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 navitia_api_client/departures_test.go (limited to 'navitia_api_client/departures_test.go') diff --git a/navitia_api_client/departures_test.go b/navitia_api_client/departures_test.go new file mode 100644 index 0000000..2c87429 --- /dev/null +++ b/navitia_api_client/departures_test.go @@ -0,0 +1,48 @@ +package navitia_api_client + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestGetDepartures(t *testing.T) { + // invalid characters in token + client := NewClient("}") + _, err := client.GetDepartures() + if err == nil { + t.Fatalf("invalid characters in token should raise an error") + } + // unreachable server + client = NewClient("https://") + _, err = client.GetDepartures() + if err == nil { + t.Fatalf("unreachable server should raise an error") + } + // invalid json + client, ts := NewTestClientFromFilename(t, "test_data/invalid.json") + defer ts.Close() + _, err = client.GetDepartures() + if err == nil { + t.Fatalf("invalid json should raise an error") + } + // http error + ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) + })) + client = NewTestClient(ts) + _, err = client.GetDepartures() + if err == nil { + t.Fatalf("404 should raise an error") + } + // normal working request + client, ts = NewTestClientFromFilename(t, "test_data/normal-crepieux.json") + defer ts.Close() + departures, err := client.GetDepartures() + if err != nil { + t.Fatalf("could not get normal-crepieux departures : %s", err) + } + if len(departures.Departures) != 10 { + t.Fatalf("did not decode normal-crepieux departures properly, got %d departures when expected 10", len(departures.Departures)) + } +} -- cgit v1.2.3