-
Notifications
You must be signed in to change notification settings - Fork 3
/
script_test.go
112 lines (106 loc) · 2.45 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package russia1
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(nil, nil)
}
func TestRussia1_ListGauges(t *testing.T) {
ts := setupTestServer()
defer ts.Close()
s := scriptRussia1{
name: "russia1",
gaugesURL: ts.URL + "/data.json",
}
expected := core.Gauges{
core.Gauge{
GaugeID: core.GaugeID{
Script: "russia1",
Code: "ЭМЕРСИТ-0249",
},
Name: "ЭМЕРСИТ-0249",
URL: "http://www.emercit.com/map/",
LevelUnit: "m",
Location: &core.Location{
Latitude: 44.473948,
Longitude: 33.803694,
Altitude: 0.0,
},
Timezone: "Europe/Moscow",
},
core.Gauge{
GaugeID: core.GaugeID{
Script: "russia1",
Code: "АГК-0034",
},
Name: "АГК-0034",
URL: "http://www.emercit.com/map/",
LevelUnit: "m",
Location: &core.Location{
Latitude: 44.32223,
Longitude: 38.70207,
Altitude: 0.0,
},
Timezone: "Europe/Moscow",
},
core.Gauge{
GaugeID: core.GaugeID{
Script: "russia1",
Code: "ЭМЕРСИТ-0007Д",
},
Name: "ЭМЕРСИТ-0007Д",
URL: "http://www.emercit.com/map/",
LevelUnit: "m",
Location: &core.Location{
Latitude: 45.0123,
Longitude: 38.997167,
Altitude: 0.0,
},
Timezone: "Europe/Moscow",
},
}
actual, err := s.ListGauges()
if assert.NoError(t, err) {
assert.Equal(t, expected, actual)
}
}
func TestRussia1_Harvest(t *testing.T) {
ts := setupTestServer()
defer ts.Close()
s := scriptRussia1{
name: "russia1",
gaugesURL: ts.URL + "/data.json",
}
expected := core.Measurements{
&core.Measurement{
GaugeID: core.GaugeID{
Script: "russia1",
Code: "ЭМЕРСИТ-0249",
},
Timestamp: core.HTime{
Time: time.Date(2020, time.March, 26, 13, 40, 0, 0, time.UTC),
},
Level: nulltype.NullFloat64Of(256.02199115753),
},
&core.Measurement{
GaugeID: core.GaugeID{
Script: "russia1",
Code: "АГК-0034",
},
Timestamp: core.HTime{
Time: time.Date(2020, time.March, 26, 13, 42, 32, 0, time.UTC),
},
Level: nulltype.NullFloat64Of(-0.19361280441284),
},
}
actual, err := core.HarvestSlice(&s, core.StringSet{}, 0)
if assert.NoError(t, err) {
assert.Equal(t, expected, actual)
}
}