From 9464c6355096153e5207cfce6716f96379252046 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 8 Jun 2023 19:18:30 +0200 Subject: [PATCH] Make formatNode test timezone independent formatNode formats the timestamp according to the current time zone. Pin the local timezone to UTC to ensure the test works everywhere. --- cmd/restic/format_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/restic/format_test.go b/cmd/restic/format_test.go index 97997945d..689bd27a5 100644 --- a/cmd/restic/format_test.go +++ b/cmd/restic/format_test.go @@ -9,6 +9,13 @@ import ( ) func TestFormatNode(t *testing.T) { + // overwrite time zone to ensure the data is formatted reproducibly + tz := time.Local + time.Local = time.UTC + defer func() { + time.Local = tz + }() + testPath := "/test/path" node := restic.Node{ Name: "baz", @@ -38,17 +45,17 @@ func TestFormatNode(t *testing.T) { Node: node, long: true, human: false, - expect: "---------- 1000 2000 14680064 2020-01-01 22:04:05 " + testPath, + expect: "---------- 1000 2000 14680064 2020-01-02 03:04:05 " + testPath, }, { path: testPath, Node: node, long: true, human: true, - expect: "---------- 1000 2000 14.000 MiB 2020-01-01 22:04:05 " + testPath, + expect: "---------- 1000 2000 14.000 MiB 2020-01-02 03:04:05 " + testPath, }, } { r := formatNode(c.path, &c.Node, c.long, c.human) - rtest.Equals(t, r, c.expect) + rtest.Equals(t, c.expect, r) } }