-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconnections_test.go
72 lines (61 loc) · 2.01 KB
/
connections_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
package navitia
import (
"context"
"reflect"
"strconv"
"testing"
"github.com/govitia/navitia/types"
)
func TestConnectionsSA(t *testing.T) {
if *apiKey == "" {
t.Skip(skipNoKey)
}
region := types.ID("fr-idf")
resources := []types.ID{
"stop_area:OIF:SA:59346",
"stop_area:OIF:SA:59586",
}
// Create the context
ctx := context.Background()
// Common request (for now)
req := ConnectionsRequest{}
// Create the run function generator, allowing us to run this in parallel
//
// Creates two versions: one calling DeparturesSA the other ArrivalsSA
rgen := func(region types.ID, resource types.ID) (func(t *testing.T), func(t *testing.T)) {
depFunc := func(t *testing.T) {
res, err := testSession.Scope(region).DeparturesSA(ctx, req, resource)
t.Log(res)
if err != nil {
t.Errorf("error in DeparturesSA: %v\n\tResource: %s\n\tParameters: %#v\n\tReceived: %#v", err, resource, req, res)
}
}
arrFunc := func(t *testing.T) {
res, err := testSession.Scope(region).ArrivalsSA(ctx, req, resource)
t.Log(res)
if err != nil {
t.Errorf("error in ArrivalsSA: %v\n\tResource: %s\n\tParameters: %#v\n\tReceived: %#v", err, resource, req, res)
}
}
return depFunc, arrFunc
}
// For each of them, let's run a subtest
for i, sa := range resources {
// Get the run function
depFunc, arrFunc := rgen(region, sa)
// Create the name
name := strconv.Itoa(i)
// Run !
t.Run(name+"_departures", depFunc)
t.Run(name+"_arrivals", arrFunc)
}
}
// Test_ConnectionsResults_Unmarshal tests unmarshalling for ConnectionsResults.
// As the unmarshalling is done in-house, this allows us to check that the custom UnmarshalJSON function correctly
//
// This launches both a "correct" and "incorrect" subtest, allowing us to test both cases.
// If we expect no errors but we get one, the test fails
// If we expect an error but we don't get one, the test fails
func Test_ConnectionsResults_Unmarshal(t *testing.T) {
testUnmarshal(t, testData["connections"], reflect.TypeOf(ConnectionsResults{}))
}