Skip to content

Commit

Permalink
stop using pointers to model structs (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
matslina authored Jan 6, 2024
1 parent 493f459 commit 7e8db92
Show file tree
Hide file tree
Showing 20 changed files with 268 additions and 280 deletions.
2 changes: 1 addition & 1 deletion parse/agency.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ParseAgency(writer storage.FeedWriter, data io.Reader) (map[string]bool, st
return nil, "", fmt.Errorf("missing agency_url")
}

writer.WriteAgency(&model.Agency{
writer.WriteAgency(model.Agency{
ID: a.ID,
Name: a.Name,
URL: a.URL,
Expand Down
12 changes: 6 additions & 6 deletions parse/agency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestParseAgency(t *testing.T) {
content string
agencyIDs map[string]bool
timezone string
agencies []*model.Agency
agencies []model.Agency
err bool
}{
{
Expand All @@ -28,7 +28,7 @@ agency_name,agency_url,agency_timezone
Agency Name,http://www.example.com,America/New_York`,
map[string]bool{"": true},
"America/New_York",
[]*model.Agency{&model.Agency{
[]model.Agency{model.Agency{
Name: "Agency Name",
URL: "http://www.example.com",
Timezone: "America/New_York",
Expand All @@ -45,20 +45,20 @@ agency_id,agency_name,agency_url,agency_timezone
3,Agency Three,http://www.example.com/three,America/New_York`,
map[string]bool{"1": true, "2": true, "3": true},
"America/New_York",
[]*model.Agency{
&model.Agency{
[]model.Agency{
model.Agency{
ID: "1",
Name: "Agency One",
URL: "http://www.example.com/one",
Timezone: "America/New_York",
},
&model.Agency{
model.Agency{
ID: "2",
Name: "Agency Two",
URL: "http://www.example.com/two",
Timezone: "America/New_York",
},
&model.Agency{
model.Agency{
ID: "3",
Name: "Agency Three",
URL: "http://www.example.com/three",
Expand Down
2 changes: 1 addition & 1 deletion parse/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func ParseCalendar(writer storage.FeedWriter, data io.Reader) (map[string]bool,
maxDate = c.EndDate
}

err = writer.WriteCalendar(&model.Calendar{
err = writer.WriteCalendar(model.Calendar{
ServiceID: c.ServiceID,
StartDate: c.StartDate,
EndDate: c.EndDate,
Expand Down
2 changes: 1 addition & 1 deletion parse/calendar_dates.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ParseCalendarDates(
maxDate = cd.Date
}

writer.WriteCalendarDate(&model.CalendarDate{
writer.WriteCalendarDate(model.CalendarDate{
ServiceID: cd.ServiceID,
Date: cd.Date,
ExceptionType: model.ExceptionType(cd.ExceptionType),
Expand Down
14 changes: 7 additions & 7 deletions parse/calendar_dates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestCalendarDates(t *testing.T) {
for _, tc := range []struct {
name string
content string
expected []*model.CalendarDate
expected []model.CalendarDate
minDate string
maxDate string
err bool
Expand All @@ -26,8 +26,8 @@ func TestCalendarDates(t *testing.T) {
`
service_id,date,exception_type
s1,20170101,1`,
[]*model.CalendarDate{
&model.CalendarDate{
[]model.CalendarDate{
model.CalendarDate{
ServiceID: "s1",
Date: "20170101",
ExceptionType: model.ExceptionTypeAdded,
Expand All @@ -45,18 +45,18 @@ service_id,date,exception_type
s1,20170101,1
s1,20170102,2
s2,20170103,1`,
[]*model.CalendarDate{
&model.CalendarDate{
[]model.CalendarDate{
model.CalendarDate{
ServiceID: "s1",
Date: "20170101",
ExceptionType: model.ExceptionTypeAdded,
},
&model.CalendarDate{
model.CalendarDate{
ServiceID: "s1",
Date: "20170102",
ExceptionType: model.ExceptionTypeRemoved,
},
&model.CalendarDate{
model.CalendarDate{
ServiceID: "s2",
Date: "20170103",
ExceptionType: model.ExceptionTypeAdded,
Expand Down
8 changes: 4 additions & 4 deletions parse/calendar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestCalendar(t *testing.T) {
for _, tc := range []struct {
name string
content string
expected []*model.Calendar
expected []model.Calendar
minDate string
maxDate string
err bool
Expand All @@ -28,7 +28,7 @@ func TestCalendar(t *testing.T) {
service_id,start_date,end_date
s,20170101,20170131`,

[]*model.Calendar{
[]model.Calendar{
{
ServiceID: "s",
Weekday: 0,
Expand All @@ -46,7 +46,7 @@ s,20170101,20170131`,
`
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
s,1,1,1,1,1,1,1,20170101,20170131`,
[]*model.Calendar{
[]model.Calendar{
{
ServiceID: "s",
Weekday: 127,
Expand All @@ -66,7 +66,7 @@ service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,e
s1,1,1,1,1,1,1,1,20170101,20170131
s2,1,1,1,1,1,0,0,20171001,20180201
s3,1,1,0,1,1,0,1,20161225,20170202`,
[]*model.Calendar{
[]model.Calendar{
{
ServiceID: "s1",
Weekday: 127,
Expand Down
16 changes: 8 additions & 8 deletions parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ func TestParseValidFeed(t *testing.T) {

agencies, err := reader.Agencies()
assert.NoError(t, err)
assert.Equal(t, []*model.Agency{&model.Agency{
assert.Equal(t, []model.Agency{model.Agency{
Timezone: "America/Los_Angeles",
Name: "Fake Agency",
URL: "http://agency/index.html",
}}, agencies)

routes, err := reader.Routes()
assert.NoError(t, err)
assert.Equal(t, []*model.Route{&model.Route{
assert.Equal(t, []model.Route{model.Route{
ID: "r",
ShortName: "R",
Type: 3,
Expand All @@ -99,7 +99,7 @@ func TestParseValidFeed(t *testing.T) {

calendar, err := reader.Calendars()
assert.NoError(t, err)
assert.Equal(t, []*model.Calendar{&model.Calendar{
assert.Equal(t, []model.Calendar{model.Calendar{
ServiceID: "mondays",
Weekday: 1 << time.Monday,
StartDate: "20190101",
Expand All @@ -108,23 +108,23 @@ func TestParseValidFeed(t *testing.T) {

calendarDates, err := reader.CalendarDates()
assert.NoError(t, err)
assert.Equal(t, []*model.CalendarDate{&model.CalendarDate{
assert.Equal(t, []model.CalendarDate{model.CalendarDate{
ServiceID: "mondays",
Date: "20190302",
ExceptionType: 1,
}}, calendarDates)

trips, err := reader.Trips()
assert.NoError(t, err)
assert.Equal(t, []*model.Trip{&model.Trip{
assert.Equal(t, []model.Trip{model.Trip{
ID: "t",
RouteID: "r",
ServiceID: "mondays",
}}, trips)

stops, err := reader.Stops()
assert.NoError(t, err)
assert.Equal(t, []*model.Stop{&model.Stop{
assert.Equal(t, []model.Stop{model.Stop{
ID: "s",
Name: "S",
Lat: 12,
Expand All @@ -133,7 +133,7 @@ func TestParseValidFeed(t *testing.T) {

stopTimes, err := reader.StopTimes()
assert.NoError(t, err)
assert.Equal(t, []*model.StopTime{&model.StopTime{
assert.Equal(t, []model.StopTime{model.StopTime{
TripID: "t",
Arrival: "120000",
Departure: "120000",
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestParseUnorthodoxArchiveStructure(t *testing.T) {

agency, err := reader.Agencies()
assert.NoError(t, err)
assert.Equal(t, []*model.Agency{&model.Agency{
assert.Equal(t, []model.Agency{model.Agency{
Timezone: "America/Los_Angeles",
Name: "Fake Agency",
URL: "http://agency/index.html",
Expand Down
2 changes: 1 addition & 1 deletion parse/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func ParseRoutes(writer storage.FeedWriter, data io.Reader, agency map[string]bo
return nil, fmt.Errorf("route_id '%s' has invalid route_text_color: %s", r.ID, r.TextColor)
}

err = writer.WriteRoute(&model.Route{
err = writer.WriteRoute(model.Route{
ID: r.ID,
AgencyID: r.AgencyID,
ShortName: r.ShortName,
Expand Down
12 changes: 6 additions & 6 deletions parse/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestParseRoutes(t *testing.T) {
name string
content string
agencies map[string]bool
routes []*model.Route
routes []model.Route
err bool
}{
{
Expand All @@ -26,7 +26,7 @@ func TestParseRoutes(t *testing.T) {
route_id,route_short_name,route_type
1,1,3`,
map[string]bool{},
[]*model.Route{&model.Route{
[]model.Route{model.Route{
ID: "1",
ShortName: "1",
Type: 3,
Expand All @@ -42,7 +42,7 @@ route_id,route_short_name,route_type
route_id,route_long_name,route_type
1,Route One,3`,
map[string]bool{},
[]*model.Route{&model.Route{
[]model.Route{model.Route{
ID: "1",
LongName: "Route One",
Type: 3,
Expand All @@ -59,8 +59,8 @@ route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_
r1,a1,one,Route One,Description1,3,http://one/,FFFFF0,00000F
r2,a2,two,Route Two,Description2,3,http://two/,FFFFF1,00000E`,
map[string]bool{"a1": true, "a2": true},
[]*model.Route{
&model.Route{
[]model.Route{
model.Route{
ID: "r1",
AgencyID: "a1",
ShortName: "one",
Expand All @@ -71,7 +71,7 @@ r2,a2,two,Route Two,Description2,3,http://two/,FFFFF1,00000E`,
Color: "FFFFF0",
TextColor: "00000F",
},
&model.Route{
model.Route{
ID: "r2",
AgencyID: "a2",
ShortName: "two",
Expand Down
3 changes: 1 addition & 2 deletions parse/stop_times.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func ParseStopTimes(
Departure: departureTime,
}

stopTimes = append(stopTimes, stopTime)
err = writer.WriteStopTime(&stopTime)
err = writer.WriteStopTime(stopTime)
if err != nil {
return errors.Wrapf(err, "writing stop_time (row %d)", i+1)
}
Expand Down
16 changes: 8 additions & 8 deletions parse/stop_times_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestParseStopTimes(t *testing.T) {
trips map[string]bool
stops map[string]bool
err bool
stopTimes []*model.StopTime
stopTimes []model.StopTime
}{
{
"minimal",
Expand All @@ -28,8 +28,8 @@ t,10:00:00,10:00:01,s,1`,
map[string]bool{"t": true},
map[string]bool{"s": true},
false,
[]*model.StopTime{
&model.StopTime{
[]model.StopTime{
model.StopTime{
TripID: "t",
Arrival: "100000",
Departure: "100001",
Expand All @@ -49,16 +49,16 @@ t,10:00:02,10:00:03,s2,2,sh2
map[string]bool{"t": true},
map[string]bool{"s1": true, "s2": true},
false,
[]*model.StopTime{
&model.StopTime{
[]model.StopTime{
model.StopTime{
TripID: "t",
Arrival: "100000",
Departure: "100001",
StopID: "s1",
StopSequence: 1,
Headsign: "sh1",
},
&model.StopTime{
model.StopTime{
TripID: "t",
Arrival: "100002",
Departure: "100003",
Expand All @@ -77,8 +77,8 @@ t,25:00:00,25:00:01,s,1`,
map[string]bool{"t": true},
map[string]bool{"s": true},
false,
[]*model.StopTime{
&model.StopTime{
[]model.StopTime{
model.StopTime{
TripID: "t",
Arrival: "250000",
Departure: "250001",
Expand Down
2 changes: 1 addition & 1 deletion parse/stops.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func ParseStops(writer storage.FeedWriter, data io.Reader) (map[string]bool, err
parentRef[st.ID] = st.ParentStation
}

err := writer.WriteStop(&stop)
err := writer.WriteStop(stop)
if err != nil {
return nil, fmt.Errorf("writing stop '%s': %w", st.ID, err)
}
Expand Down
Loading

0 comments on commit 7e8db92

Please sign in to comment.