59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package cif
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
|
|
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
|
|
)
|
|
|
|
func TestGenerateMetadata(t *testing.T) {
|
|
header := &upstreamApi.JsonTimetableV1{
|
|
Classification: "public",
|
|
Timestamp: 1711227636,
|
|
Owner: "Network Rail",
|
|
Sender: upstreamApi.TimetableSender{
|
|
Organisation: "Rockshore",
|
|
Application: "NTROD",
|
|
Component: "SCHEDULE",
|
|
},
|
|
Metadata: upstreamApi.TimetableMetadata{
|
|
Type: "update",
|
|
Sequence: 4307,
|
|
},
|
|
}
|
|
|
|
expected := &dbAccess.CifMetadata{
|
|
Doctype: dbAccess.Doctype,
|
|
LastTimestamp: header.Timestamp,
|
|
LastSequence: header.Metadata.Sequence,
|
|
LastUpdate: time.Now().In(londonTimezone),
|
|
}
|
|
|
|
result := generateMetadata(header)
|
|
|
|
if result == nil {
|
|
t.Errorf("generateMetadata returned nil pointer")
|
|
return // Static type checking likes this return to be here, even if it is redundant in reality.
|
|
}
|
|
|
|
if result.Doctype != expected.Doctype {
|
|
t.Errorf("Doctype: expected %s, got %s", expected.Doctype, result.Doctype)
|
|
}
|
|
|
|
if result.LastTimestamp != expected.LastTimestamp {
|
|
t.Errorf("LastTimestamp: expected %d, got %d", expected.LastTimestamp, result.LastTimestamp)
|
|
}
|
|
|
|
if result.LastSequence != expected.LastSequence {
|
|
t.Errorf("LastSequence: expected %d, got %d", expected.LastSequence, result.LastSequence)
|
|
}
|
|
|
|
tolerance := time.Second
|
|
if !result.LastUpdate.Before(expected.LastUpdate.Add(tolerance)) ||
|
|
!result.LastUpdate.After(expected.LastUpdate.Add(-tolerance)) {
|
|
t.Errorf("LastUpdate: expected %s, got %s", expected.LastUpdate, result.LastUpdate)
|
|
}
|
|
}
|