-
Notifications
You must be signed in to change notification settings - Fork 2
/
forecast_test.go
57 lines (47 loc) · 1.04 KB
/
forecast_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package surflinef
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestAnalysis(t *testing.T) {
d, err := ioutil.ReadFile("fixtures/forecast.json")
if err != nil {
t.Fatal(err)
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write(d)
}))
defer ts.Close()
bu, err := url.Parse(ts.URL)
if err != nil {
t.Fatal(err)
}
c := Client{BaseURL: bu, httpClient: http.DefaultClient}
q := Query{
Resources: []string{"surf,analysis,wind,weather,tide"},
Days: 1,
Units: "e",
}
qs, err := q.QueryString()
if err != nil {
t.Fatal(err)
}
f, err := c.GetForecast("2141", qs)
if err != nil {
t.Fatal(err)
}
a := f.Analysis
cond := "FAIR"
if a.GeneralCondition[0] != cond {
t.Errorf("Got '%s', expected '%s'", a.GeneralCondition[0], cond)
}
min := "0"
if a.SurfMin[0] != min {
t.Errorf("Got '%s', expected '%s'", a.SurfMin[0], min)
}
}