From 505edf74c9a0405391e2520a0c4ea7957fbc098d Mon Sep 17 00:00:00 2001 From: Matthias Hannig Date: Mon, 16 Jul 2018 16:51:13 +0200 Subject: [PATCH] updated test to cover state_changed in neighbor-summary --- backend/sources/birdwatcher/parsers_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/sources/birdwatcher/parsers_test.go b/backend/sources/birdwatcher/parsers_test.go index 6edf57b..fad0c80 100644 --- a/backend/sources/birdwatcher/parsers_test.go +++ b/backend/sources/birdwatcher/parsers_test.go @@ -93,7 +93,10 @@ func Test_NeighboursParsing(t *testing.T) { } func Test_NeighborSummaryParsing(t *testing.T) { - config := Config{Timezone: "UTC"} // Or "" + + config := Config{ + Timezone: "UTC", + ServerTimeShort: "2006-01-02 15:04:05"} // Or "" bird, err := loadTestResponse("../../testdata/api/neighbor_summary.json") if err != nil { t.Error(err) @@ -128,8 +131,17 @@ func Test_NeighborSummaryParsing(t *testing.T) { t.Error("Unexpected description:", n.Description) } - if n.Uptime != 7038818900526 { - t.Error("Unexpected uptime:", n.Uptime) + // Uptime is relative to the last_change timestamp, + // so the value is shifting. Calculate the expected value first: + lastChange := time.Date(2018, 7, 14, 15, 8, 30, 0, time.UTC) + expectedUptime := time.Since(lastChange) + uptimeDiff := expectedUptime - n.Uptime + + if uptimeDiff > 1*time.Second { + t.Error( + "Unexpected uptime:", n.Uptime, + "diverges more than 1 s from expected value", + ) } if n.RoutesReceived != 154 {