-
Notifications
You must be signed in to change notification settings - Fork 3
/
script_test.go
76 lines (71 loc) · 1.7 KB
/
script_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package galicia2
import (
"net/http/httptest"
"testing"
"time"
"github.com/mattn/go-nulltype"
"github.com/stretchr/testify/assert"
"github.com/whitewater-guide/gorge/core"
"github.com/whitewater-guide/gorge/testutils"
)
func setupTestServer() *httptest.Server {
return testutils.SetupFileServer(map[string]string{
"/table": "table.xls",
"": "A015.html",
}, nil)
}
func TestGalicia2_ListGauges(t *testing.T) {
ts := setupTestServer()
defer ts.Close()
s := scriptGalicia2{
name: "galicia2",
listURL: ts.URL + "/table.xls",
gaugeURLFormat: ts.URL + "/%s.html",
skipCookies: true,
}
actual, err := s.ListGauges()
expected := core.Gauge{
GaugeID: core.GaugeID{
Script: "galicia2",
Code: "A015",
},
LevelUnit: "m",
Location: &core.Location{
Latitude: 42.87182,
Longitude: -7.52761,
Altitude: 348.65,
},
Name: "Río Neira en Páramo (o)",
URL: ts.URL + "/A015.html",
Timezone: "Europe/Madrid",
}
if assert.NoError(t, err) {
assert.Len(t, actual, 58)
assert.Contains(t, actual, expected)
}
}
func TestGalicia2_Harvest(t *testing.T) {
ts := setupTestServer()
defer ts.Close()
s := scriptGalicia2{
name: "galicia2",
listURL: ts.URL + "/table.xls",
gaugeURLFormat: ts.URL + "/%s.html",
skipCookies: true,
}
actual, err := core.HarvestSlice(&s, core.StringSet{}, 0)
expected := &core.Measurement{
GaugeID: core.GaugeID{
Script: "galicia2",
Code: "A015",
},
Timestamp: core.HTime{
Time: time.Date(2020, time.January, 23, 8, 0, 0, 0, time.UTC),
},
Level: nulltype.NullFloat64Of(0.44),
}
if assert.NoError(t, err) {
assert.Len(t, actual, 58)
assert.Contains(t, actual, expected)
}
}