Skip to content

Commit

Permalink
tests: fix multi-line strings ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Jun 23, 2024
1 parent c1bd4ee commit c222316
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
12 changes: 8 additions & 4 deletions test/amtrak-gtfs-2021-10-06.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ from amtrak.arrivals_departures
where stop_id = 'BHM' -- Birmingham
and date = '2021-11-26'
order by t_arrival
EOF)
EOF
)

# 2021-11-26T15:15:00-05:00
arr1=$(psql --csv -t -c "$query" | head -n 1)
Expand Down Expand Up @@ -63,7 +64,8 @@ FROM amtrak.stats_by_route_date
WHERE route_id = '40751' -- Acela
AND date = '2021-11-26'
AND is_effective = True
EOF)
EOF
)
acelaStat=$(psql --csv -t -c "$acelaStatQuery" | tail -n 1)
if [[ "$acelaStat" != "16,190" ]]; then
echo "invalid stats for route 40751 (Acela) on 2021-11-26: $acelaStat" 1>&2
Expand All @@ -76,7 +78,8 @@ FROM amtrak.stats_by_agency_route_stop_hour
WHERE route_id = '40751' -- Acela
AND stop_id = 'PHL' -- Philadelphia
AND effective_hour = '2022-07-24T09:00-05'
EOF)
EOF
)
acelaPhillyStat=$(psql --csv -t -c "$acelaPhillyStatQuery" | tail -n 1)
if [[ "$acelaPhillyStat" != "2" ]]; then
echo "invalid stats for route 40751 (Acela) at PHL (Philadelphia) on 2021-11-26: $acelaPhillyStat" 1>&2
Expand All @@ -87,7 +90,8 @@ nrOfActiveTripsQuery=$(cat << EOF
SELECT nr_of_active_trips
FROM amtrak.stats_active_trips_by_hour
WHERE "hour" = '2021-11-26T04:00-05'
EOF)
EOF
)
# Note: I'm not sure if 127 is correct, but it is in the right ballpark. 🙈
# The following query yields 150 connections, and it doesn't contain those who depart earlier and arrive later.
# SELECT DISTINCT ON (trip_id) *
Expand Down
9 changes: 6 additions & 3 deletions test/calendar-dates-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ select extract(epoch from t_arrival)::integer as t_arrival
from arrivals_departures
where stop_id = 'museum'
order by t_arrival
EOF)
EOF
)

# 2019-07-15T15:30:00+02:00
arr1=$(psql --csv -t -c "$query" | head -n 1)
Expand All @@ -40,7 +41,8 @@ agency_id_null=$(cat << EOF
select count(*)
from arrivals_departures
where agency_id IS NULL
EOF)
EOF
)
agency_id_null_count="$(psql --csv -t -c "$agency_id_null")"
if [[ "$agency_id_null_count" != "0" ]]; then
echo ">0 rows with agency_id = null" 1>&2
Expand All @@ -53,7 +55,8 @@ SELECT DISTINCT ON (stop_id)
wheelchair_boarding
FROM arrivals_departures
ORDER BY stop_id, trip_id
EOF)
EOF
)
wheelchair_boarding_rows="$(psql --csv -t -c "$wheelchair_boarding_query")"
wheelchair_boarding_expected="$(echo -e "airport,accessible\nairport-1,not_accessible\nlake,no_info_or_inherit\nmuseum,no_info_or_inherit")"
if [[ "$wheelchair_boarding_rows" != "$wheelchair_boarding_expected" ]]; then
Expand Down
6 changes: 4 additions & 2 deletions test/multiple-schemas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ WHERE (
OR a.level_id IS DISTINCT FROM b.level_id
OR a.platform_code IS DISTINCT FROM b.platform_code
)
EOF)
EOF
)

unequal_stops_1=$(psql --csv -t -c "$nr_of_unequal_stops" | head -n 1)
if [[ "$unequal_stops_1" -ne 0 ]]; then
Expand All @@ -63,7 +64,8 @@ AS \$\$
SELECT '0.1.2'
\$\$
LANGUAGE SQL
EOF)"
EOF
)"

# expect another import to fail
if ../cli.js -d --trips-without-shape-id \
Expand Down
51 changes: 34 additions & 17 deletions test/sample-gtfs-feed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ select extract(epoch from t_arrival)::integer as t_arrival
from arrivals_departures
where route_id = 'D'
order by t_arrival
EOF)
EOF
)

arr1=$(psql --csv -t -c "$query" | head -n 1)
if [[ "$arr1" != "1553993700" ]]; then
Expand All @@ -55,7 +56,8 @@ arrs_deps_b_downtown_on_working_days=$(cat << EOF
WHERE trip_id = 'b-downtown-on-working-days'
ORDER BY t_departure
LIMIT 2
EOF)
EOF
)
freq_arr_dep1=$(psql --csv -t -c "$arrs_deps_b_downtown_on_working_days" | head -n 1)
if [[ "$freq_arr_dep1" != "1,1552028340,1552028400,1,1" ]]; then
echo "invalid/missing frequencies-based arrival/departure: $freq_arr_dep1" 1>&2
Expand All @@ -77,7 +79,8 @@ cons_b_downtown_on_working_days=$(cat << EOF
WHERE trip_id = 'b-downtown-on-working-days'
ORDER BY t_departure
LIMIT 1
EOF)
EOF
)
freq_con1=$(psql --csv -t -c "$cons_b_downtown_on_working_days")
if [[ "$freq_con1" != "1,1552028400,3,1552028760" ]]; then
echo "invalid/missing frequencies-based connection: $freq_con1" 1>&2
Expand All @@ -91,7 +94,8 @@ connection_during_dst=$(cat << EOF
FROM connections
WHERE trip_id = 'during-dst-1'
AND t_departure = '2019-03-31T01:58+01'
EOF)
EOF
)
dst1=$(psql --csv -t -c "$connection_during_dst" | head -n 1)
if [[ "$dst1" != "0,1553993880" ]]; then
echo "invalid/missing DST t_departure: $dst1" 1>&2
Expand All @@ -107,7 +111,8 @@ airport_levels=$(cat << EOF
WHERE level_id LIKE 'airport-%'
ORDER BY level_index
LIMIT 1
EOF)
EOF
)
lvl1=$(psql --csv -t -c "$airport_levels" | head -n 1)
if [[ "$lvl1" != "airport-level-0,0,ground level" ]]; then
echo "invalid/missing lowest airport-% level: $lvl1" 1>&2
Expand All @@ -122,7 +127,8 @@ airportPathway=$(cat << EOF
WHERE from_stop_id = 'airport-entrance'
AND to_stop_id = 'airport-1-access'
LIMIT 1
EOF)
EOF
)
pw1=$(psql --csv -t -c "$airportPathway" | head -n 1)
if [[ "$pw1" != "escalator,f" ]]; then
echo "invalid/missing DST t_departure: $pw1" 1>&2
Expand All @@ -135,7 +141,8 @@ timepoint_exact=$(cat << EOF
WHERE timepoint = 'exact'
AND stop_sequence_consec = 0
LIMIT 1
EOF)
EOF
)
exact1=$(psql --csv -t -c "$timepoint_exact" | head -n 1)
if [[ "$exact1" != "exact" ]]; then
echo "invalid/missing DST t_departure: $exact1" 1>&2
Expand All @@ -148,7 +155,8 @@ stops_translations=$(cat << EOF
WHERE table_name = 'stops' AND field_name = 'stop_name'
AND language = 'de-DE'
AND record_id = 'airport-entrance'
EOF)
EOF
)
airport_entrance_translation=$(psql --csv -t -c "$stops_translations")
if [[ "$airport_entrance_translation" != "Eingang,de-DE" ]]; then
echo "invalid/missing stop translation: $airport_entrance_translation" 1>&2
Expand All @@ -163,7 +171,8 @@ stops_translated=$(cat << EOF
FROM stops_translated
WHERE (stop_name_lang IS NULL or stop_name_lang = 'de-DE')
AND stop_id = 'airport-entrance'
EOF)
EOF
)
translated_airport_entrance=$(psql --csv -t -c "$stops_translated")
if [[ "$translated_airport_entrance" != "airport-entrance,Eingang,de-DE" ]]; then
echo "invalid/missing translated stop: $translated_airport_entrance" 1>&2
Expand All @@ -176,7 +185,8 @@ SELECT DISTINCT ON (trip_id)
FROM arrivals_departures
WHERE route_id = ANY(ARRAY['A', 'B'])
ORDER BY trip_id
EOF)
EOF
)
wheelchair_accessible_arrs_deps_rows="$(psql --csv -t -c "$wheelchair_accessible_arrs_deps_query")"
wheelchair_accessible_arrs_deps_expected=$(cat << EOF
a-downtown-all-day,
Expand All @@ -185,7 +195,8 @@ b-downtown-on-weekends,accessible
b-downtown-on-working-days,accessible
b-outbound-on-weekends,unknown
b-outbound-on-working-days,unknown
EOF)
EOF
)
if [[ "$wheelchair_accessible_arrs_deps_rows" != "$wheelchair_accessible_arrs_deps_expected" ]]; then
echo "arrivals_departures: invalid wheelchair_accessible values" 1>&2
exit 1
Expand All @@ -197,7 +208,8 @@ SELECT DISTINCT ON (trip_id)
FROM arrivals_departures
WHERE route_id = ANY(ARRAY['A', 'B'])
ORDER BY trip_id
EOF)
EOF
)
bikes_allowed_arrs_deps_rows="$(psql --csv -t -c "$bikes_allowed_arrs_deps_query")"
bikes_allowed_arrs_deps_expected=$(cat << EOF
a-downtown-all-day,
Expand All @@ -206,7 +218,8 @@ b-downtown-on-weekends,unknown
b-downtown-on-working-days,unknown
b-outbound-on-weekends,allowed
b-outbound-on-working-days,allowed
EOF)
EOF
)
if [[ "$bikes_allowed_arrs_deps_rows" != "$bikes_allowed_arrs_deps_expected" ]]; then
echo "arrivals_departures: invalid bikes_allowed values" 1>&2
exit 1
Expand All @@ -216,13 +229,15 @@ frequencies_it_query=$(cat << EOF
SELECT t_departure, stop_sequence, stop_id frequencies_it
FROM arrivals_departures
WHERE trip_id = 'b-downtown-on-working-days' AND "date" = '2019-05-29' AND frequencies_it = 3
EOF)
EOF
)
frequencies_it_rows="$(psql --csv -t -c "$frequencies_it_query")"
frequencies_it_expected=$(cat << EOF
2019-05-29 08:10:00+02,1,airport
2019-05-29 08:18:00+02,3,lake
2019-05-29 08:27:00+02,5,center
EOF)
EOF
)
if [[ "$frequencies_it_rows" != "$frequencies_it_expected" ]]; then
echo "arrivals_departures with frequencies_it=3" 1>&2
exit 1
Expand All @@ -236,7 +251,8 @@ SELECT
stop_url, stop_url_lang
FROM stops_translated
WHERE stop_id LIKE 'airport%'
EOF)
EOF
)
stops_translated_rows="$(psql --csv -t -c "$stops_translated_query")"
stops_translated_expected=$(cat << EOF
airport,International Airport (ABC),,train station at the Internationl Airport (ABC),,https://example.org#AT,de-AT
Expand All @@ -246,7 +262,8 @@ airport-2,Platform 2,,Platform 2,,,
airport-2-access,,,,,,
airport-2-boarding,pl. 2 boarding,,platform 2 boarding area,,,
airport-entrance,Eingang,de-DE,,,,
EOF)
EOF
)
if [[ "$stops_translated_rows" != "$stops_translated_expected" ]]; then
echo "stops_translated with stop_id=airport*" 1>&2
exit 1
Expand Down

0 comments on commit c222316

Please sign in to comment.