-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluas_test.go
112 lines (107 loc) · 2.67 KB
/
luas_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 luas
import (
"errors"
"io/ioutil"
"path/filepath"
"testing"
)
func TestXMLUnmarshalling(t *testing.T) {
testTable := []struct {
Name string
TestXMLFile string
Stop string
StopAbv string
Message string
Inbound Direction
Outbound Direction
}{
{
"Balally",
"balally.xml",
"Balally",
"BAL",
"Green Line services operating normally",
Direction{
Name: "Inbound",
Trams: []Tram{
Tram{
DueMins: "3",
Destination: "Parnell",
},
Tram{
DueMins: "DUE",
Destination: "Broombridge",
},
},
},
Direction{
Name: "Outbound",
Trams: []Tram{
Tram{
DueMins: "9",
Destination: "Bride's Glen",
},
},
},
},
}
for _, testCase := range testTable {
t.Run(testCase.Name, func(t *testing.T) {
xmlDataFile := filepath.Join("testdata", testCase.TestXMLFile)
bytes, err := ioutil.ReadFile(xmlDataFile)
if err != nil {
t.Fatalf("error reading fixtures file %v, %v", testCase.TestXMLFile, err)
}
stopInfo, err := parseLuasResponse(bytes)
if err != nil {
t.Fatalf("cannot parse luas response xml, %v", err)
}
assert(t, "stop should be equal", testCase.Stop, stopInfo.Stop)
assert(t, "stop abv should be equal", testCase.StopAbv, stopInfo.StopAbv)
assert(t, "message should be equal", testCase.Message, stopInfo.Message)
// TODO test tram by tram
})
}
}
func TestGetStop(t *testing.T) {
testTable := []struct {
Name string
StopName string
ExpectedStop *Stop
ExpectedErr error
}{
{"existing stop should return the stop", "BAL", &Stop{
Name: "Balally",
NameAbv: "BAL",
Line: "green",
Coordinates: []float64{53.28610556, -6.236772222},
}, nil},
{"non existing stop should return an error", "IKO", &Stop{}, errors.New("no such stop IKO")},
{"get existing stop by long name", "Balally", &Stop{
Name: "Balally",
NameAbv: "BAL",
Line: "green",
Coordinates: []float64{53.28610556, -6.236772222},
}, nil},
}
for _, testCase := range testTable {
t.Run(testCase.Name, func(t *testing.T) {
stop, err := GetStop(testCase.StopName)
if stop.NameAbv != testCase.ExpectedStop.NameAbv || // TODO uncomplicate this thing
((err != nil || testCase.ExpectedErr != nil) && err.Error() != testCase.ExpectedErr.Error()) {
t.Fatalf(
"expected stop %v and err %v, got stop %v and err %v",
testCase.ExpectedStop,
testCase.ExpectedErr,
stop,
err,
)
}
})
}
}
func assert(t *testing.T, message string, a interface{}, b interface{}) {
if a != b {
t.Fatalf(message, "%s: expected %v, got %v", message, a, b)
}
}