aboutsummaryrefslogtreecommitdiffstats
path: root/entur/entur_test.go
blob: 1555bb8b9a992f940f2ec6b3c03fa734374ca2f6 (plain) (blame)
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
package entur

import (
	"io/ioutil"
	"path/filepath"
	"testing"
	"time"
)

func TestParseDepartures(t *testing.T) {
	testFile := filepath.Join("testdata", "ilsvika.json")
	json, err := ioutil.ReadFile(testFile)
	if err != nil {
		t.Fatal(err)
	}
	d, err := parseDepartures(json)
	if err != nil {
		t.Fatal(err)
	}
	cest := time.FixedZone("CEST", 7200)
	expected := []Departure{
		{
			Line:                    "21",
			RegisteredDepartureTime: time.Time{},
			ScheduledDepartureTime:  time.Date(2022, 5, 20, 18, 19, 0, 0, cest),
			Destination:             "Pirbadet via sentrum",
			IsRealtime:              true,
			Inbound:                 false,
		},
		{
			Line:                    "21",
			RegisteredDepartureTime: time.Time{},
			ScheduledDepartureTime:  time.Date(2022, 5, 20, 19, 19, 0, 0, cest),
			Destination:             "Pirbadet via sentrum",
			IsRealtime:              true,
			Inbound:                 false,
		},
		{
			Line:                    "21",
			RegisteredDepartureTime: time.Time{},
			ScheduledDepartureTime:  time.Date(2022, 5, 20, 20, 19, 0, 0, cest),
			Destination:             "Pirbadet via sentrum",
			IsRealtime:              true,
			Inbound:                 false,
		},
	}
	for i := 0; i < len(expected); i++ {
		got := d[i]
		want := expected[i]
		if want.Line != got.Line {
			t.Errorf("#%d: want Line = %q, got %q", i, want.Line, got.Line)
		}
		if !want.RegisteredDepartureTime.Equal(got.RegisteredDepartureTime) {
			t.Errorf("#%d: want RegisteredDepartureTime = %q, got %q", i, want.RegisteredDepartureTime, got.RegisteredDepartureTime)
		}
		if !want.ScheduledDepartureTime.Equal(got.ScheduledDepartureTime) {
			t.Errorf("#%d: want ScheduledDepartureTime = %q, got %q", i, want.ScheduledDepartureTime, got.ScheduledDepartureTime)
		}
		if want.Destination != got.Destination {
			t.Errorf("#%d: want Destination = %q, got %q", i, want.Destination, got.Destination)
		}
		if want.IsRealtime != got.IsRealtime {
			t.Errorf("#%d: want IsRealtime = %t, got %t", i, want.IsRealtime, got.IsRealtime)
		}
		if want.Inbound != got.Inbound {
			t.Errorf("#%d: want Inbound = %t, got %t", i, want.Inbound, got.Inbound)
		}
	}
}