Add test for parseStops

This commit is contained in:
Fred Boniface 2024-04-08 19:33:00 +01:00
parent 04a5600ca6
commit feb7ee0fdf
1 changed files with 50 additions and 0 deletions

View File

@ -1,8 +1,10 @@
package cif package cif
import ( import (
"reflect"
"testing" "testing"
"git.fjla.uk/owlboard/go-types/pkg/database"
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi" "git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
) )
@ -159,3 +161,51 @@ func TestHasSleeper(t *testing.T) {
t.Errorf("hasSleeper failed to handle nil pointer, expected %t, but got %t", false, nilResult) t.Errorf("hasSleeper failed to handle nil pointer, expected %t, but got %t", false, nilResult)
} }
} }
func TestParseStops(t *testing.T) {
testCases := []struct {
input []upstreamApi.CifScheduleLocation
expected []database.Stop
}{
{
input: []upstreamApi.CifScheduleLocation{
{
LocationType: "LO",
RecordIdentity: "Yes",
TiplocCode: "BATHSPA",
TiplocInstance: "0",
Arrival: "0445",
Departure: "0449",
PublicDeparture: "0449",
Pass: "",
Platform: "1",
Line: "DM",
Path: "DM",
EngineeringAllowance: "",
PathingAllowance: "",
PerformanceAllowance: "",
}},
expected: []database.Stop{
{
PublicDeparture: "0449",
WttDeparture: "0449",
PublicArrival: "",
WttArrival: "0445",
IsPublic: true,
Tiploc: "BATHSPA",
Pass: "",
Platform: "1",
ArrLine: "DM",
DepLine: "DM",
},
},
},
}
for _, tc := range testCases {
result := parseStops(&tc.input)
if !reflect.DeepEqual(result, tc.expected) {
t.Errorf("Test case failed. Input: %v, Expected: %v, Got: %v", tc.input, tc.expected, result)
}
}
}