@@ -10,7 +10,7 @@ import (
1010 "testing"
1111 "time"
1212
13- remoteGtfs "github.com/jamespfennell/ gtfs"
13+ remoteGtfs "github.com/OneBusAway/go- gtfs"
1414 "watchdog.onebusaway.org/internal/geo"
1515 "watchdog.onebusaway.org/internal/models"
1616)
@@ -56,7 +56,6 @@ func TestDownloadGTFSBundle(t *testing.T) {
5656 if staticBundle == nil {
5757 t .Fatal ("static data retrieved from the store is nil; expected non-nil value" )
5858 }
59-
6059 data := readFixture (t , "gtfs.zip" )
6160 expectedStaticData , err := remoteGtfs .ParseStatic (data , remoteGtfs.ParseStaticOptions {})
6261 if err != nil {
@@ -109,6 +108,151 @@ func TestDownloadGTFSBundle(t *testing.T) {
109108
110109}
111110
111+ func TestAgencyParsing (t * testing.T ) {
112+ data := readFixture (t , "gtfs.zip" )
113+ staticBundle , err := remoteGtfs .ParseStatic (data , remoteGtfs.ParseStaticOptions {})
114+ if err != nil {
115+ t .Fatalf ("failed to parse expected GTFS static data from fixture: %v" , err )
116+ }
117+
118+ expectedStaticAgencies := []remoteGtfs.Agency {
119+ {
120+ Id : "40" ,
121+ Name : "Sound Transit" ,
122+ Url : "https://www.soundtransit.org" ,
123+ Timezone : "America/Los_Angeles" ,
124+ Language : "en" ,
125+ Phone : "1-888-889-6368" ,
126+ FareUrl : "https://www.soundtransit.org/ride-with-us/how-to-pay/fares" ,
127+ Email : "main@soundtransit.org" ,
128+ },
129+ }
130+
131+ if staticBundle .Agencies == nil {
132+ t .Fatal ("stored static data has nil Agencies slice; expected it to be populated" )
133+ }
134+ if len (staticBundle .Agencies ) == 0 {
135+ t .Fatal ("stored Agencies slice is empty; static data likely not parsed correctly" )
136+ }
137+
138+ if len (expectedStaticAgencies ) != len (staticBundle .Agencies ) {
139+ t .Fatalf ("expected %d agencies, got %d" , len (expectedStaticAgencies ), len (staticBundle .Agencies ))
140+ }
141+
142+ expectedAgencies := make (map [string ]remoteGtfs.Agency )
143+
144+ for _ , agency := range expectedStaticAgencies {
145+ expectedAgencies [agency .Id ] = remoteGtfs.Agency {
146+ Id : agency .Id ,
147+ Name : agency .Name ,
148+ Timezone : agency .Timezone ,
149+ Url : agency .Url ,
150+ FareUrl : agency .FareUrl ,
151+ Language : agency .Language ,
152+ Phone : agency .Phone ,
153+ Email : agency .Email ,
154+ }
155+ }
156+
157+ for _ , agency := range staticBundle .Agencies {
158+ expectedAgency , ok := expectedAgencies [agency .Id ]
159+ if ! ok {
160+ t .Fatalf ("unexpected agency ID %s" , agency .Id )
161+ }
162+
163+ if expectedAgency != agency {
164+ t .Errorf (
165+ "agency mismatch for ID %s expected: %+v got %+v" ,
166+ agency .Id ,
167+ expectedAgency ,
168+ agency ,
169+ )
170+ }
171+ }
172+ }
173+
174+ func TestStopsParsing (t * testing.T ) {
175+ server := models.ObaServer {ID : 1 , Name : "test" }
176+
177+ data := readFixture (t , "gtfs.zip" )
178+ staticBundle , err := remoteGtfs .ParseStatic (data , remoteGtfs.ParseStaticOptions {})
179+ if err != nil {
180+ t .Fatal ("failed to parse gtfs static data" )
181+ }
182+ staticData := models .NewStaticData (staticBundle )
183+ staticStore := NewStaticStore ()
184+ staticStore .Set (server .ID , staticData )
185+ stopIDs := []string {"11060" , "1108" } // Make sure these exist in your test GTFS
186+ stopsData := map [string ]struct {
187+ stopName string
188+ lat float64
189+ long float64
190+ }{
191+ "11060" : {stopName : "Broadway & E Denny Way" , lat : 47.618425 , long : - 122.320940 },
192+ "1108" : {stopName : "Westlake" , lat : 47.611450 , long : - 122.337532 },
193+ }
194+
195+ stops , err := getStopLocationsByIDs (server .ID , stopIDs , staticStore )
196+ if err != nil {
197+ t .Fatalf ("unexpected error: %v" , err )
198+ }
199+ if len (stops ) == 0 {
200+ t .Fatalf ("expected some matched stops, got 0" )
201+ }
202+
203+ for _ , stop := range stops {
204+ expected , ok := stopsData [stop .Id ]
205+ if ! ok {
206+ t .Fatalf ("unexpected stop ID returned: %s" , stop .Id )
207+ }
208+ if stop .Latitude == nil || stop .Longitude == nil {
209+ t .Fatalf ("stop %s missing coordinates" , stop .Id )
210+ }
211+
212+ if stop .Name != expected .stopName {
213+ t .Errorf ("stop %s name mismatch: expected %s, got %s" ,
214+ stop .Id , expected .stopName , stop .Name )
215+ }
216+
217+ const epsilon = 1e-5
218+ if diff := * stop .Latitude - expected .lat ; diff > epsilon || diff < - epsilon {
219+ t .Errorf ("stop %s latitude mismatch: expected %f, got %f" ,
220+ stop .Id , expected .lat , * stop .Latitude )
221+ }
222+ if diff := * stop .Longitude - expected .long ; diff > epsilon || diff < - epsilon {
223+ t .Errorf ("stop %s longitude mismatch: expected %f, got %f" ,
224+ stop .Id , expected .long , * stop .Longitude )
225+ }
226+ }
227+ }
228+
229+ func TestGetEarliestAndLatestServiceDates (t * testing.T ) {
230+ server := models.ObaServer {ID : 1 , Name : "test" }
231+ data := readFixture (t , "gtfs.zip" )
232+ staticBundle , err := remoteGtfs .ParseStatic (data , remoteGtfs.ParseStaticOptions {})
233+ if err != nil {
234+ t .Fatal ("failed to parse gtfs static data" )
235+ }
236+ staticData := models .NewStaticData (staticBundle )
237+ staticStore := NewStaticStore ()
238+ staticStore .Set (server .ID , staticData )
239+ loc , _ := time .LoadLocation ("America/Los_Angeles" )
240+ // make sure these already exist in the test data
241+ expectedEarliestEndDate := time .Date (2024 , 11 , 22 , 0 , 0 , 0 , 0 , loc )
242+ expectedLatestEndDate := time .Date (2025 , 03 , 28 , 0 , 0 , 0 , 0 , loc )
243+ actualEarliest , actualLatest , err := getEarliestAndLatestServiceDates (staticData )
244+ if err != nil {
245+ t .Fatalf ("unexpected error: %v" , err )
246+ }
247+
248+ if ! expectedEarliestEndDate .Equal (actualEarliest ) {
249+ t .Fatalf ("earliest date mismatch: expected %s, got %s" , expectedEarliestEndDate .Format ("2006-01-02" ), actualEarliest .Format ("2006-01-02" ))
250+ }
251+ if ! expectedLatestEndDate .Equal (actualLatest ) {
252+ t .Fatalf ("latest date mismatch: expected %s, got %s" , expectedLatestEndDate .Format ("2006-01-02" ), actualLatest .Format ("2006-01-02" ))
253+ }
254+ }
255+
112256func TestGetStopLocationsByIDs (t * testing.T ) {
113257 server := models.ObaServer {ID : 1 , Name : "test" }
114258
@@ -121,7 +265,7 @@ func TestGetStopLocationsByIDs(t *testing.T) {
121265 staticStore := NewStaticStore ()
122266 staticStore .Set (server .ID , staticData )
123267
124- t .Run ("Valid stop IDs" , func (t * testing.T ) {
268+ t .Run ("Valid stops IDs" , func (t * testing.T ) {
125269 stopIDs := []string {"11060" , "1108" } // Make sure these exist in your test GTFS
126270 stops , err := getStopLocationsByIDs (server .ID , stopIDs , staticStore )
127271 if err != nil {
@@ -187,19 +331,21 @@ func TestFetchAndStoreGTFSRTFeed(t *testing.T) {
187331 t .Fatalf ("Expected %d vehicles, got %d" , len (expectedRtData .Vehicles ), len (realtimeData .Vehicles ))
188332 }
189333
190- expectedMap := make (map [string ]struct {} )
334+ expectedMap := make (map [string ]remoteGtfs. Vehicle )
191335 for _ , vehicle := range expectedRtData .Vehicles {
192336 if vehicle .ID != nil {
193- expectedMap [vehicle .ID .ID ] = struct {}{}
337+ expectedMap [vehicle .ID .ID ] = vehicle
194338 }
195339 }
196340 countExpectedNilIDs := len (expectedRtData .Vehicles ) - len (expectedMap )
197341 countNilIDs := 0
198342 for _ , vehicle := range realtimeData .Vehicles {
199343 if vehicle .ID != nil {
200- if _ , exists := expectedMap [vehicle .ID .ID ]; ! exists {
344+ expectedVehicle , exists := expectedMap [vehicle .ID .ID ]
345+ if ! exists {
201346 t .Errorf ("Unexpected vehicle ID %s found in GTFS-RT data" , vehicle .ID .ID )
202347 }
348+ assertVehicle (t , & vehicle , & expectedVehicle )
203349 } else {
204350 countNilIDs ++
205351 }
0 commit comments