From feb7ee0fdf204b45481301737e707b28ef57616e Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 8 Apr 2024 19:33:00 +0100 Subject: [PATCH] Add test for parseStops --- cif/convert_test.go | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/cif/convert_test.go b/cif/convert_test.go index c15e500..0d78908 100644 --- a/cif/convert_test.go +++ b/cif/convert_test.go @@ -1,8 +1,10 @@ package cif import ( + "reflect" "testing" + "git.fjla.uk/owlboard/go-types/pkg/database" "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) } } + +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) + } + } +}