2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-24 05:37:37 +00:00

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.
This commit is contained in:
Michael Eischer 2023-06-08 19:18:30 +02:00
parent 6ebf2dd235
commit 9464c63550

View File

@ -9,6 +9,13 @@ import (
) )
func TestFormatNode(t *testing.T) { 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" testPath := "/test/path"
node := restic.Node{ node := restic.Node{
Name: "baz", Name: "baz",
@ -38,17 +45,17 @@ func TestFormatNode(t *testing.T) {
Node: node, Node: node,
long: true, long: true,
human: false, 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, path: testPath,
Node: node, Node: node,
long: true, long: true,
human: 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) r := formatNode(c.path, &c.Node, c.long, c.human)
rtest.Equals(t, r, c.expect) rtest.Equals(t, c.expect, r)
} }
} }