2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-03 09:30:50 +00:00
restic/cmd/restic/format_test.go
Michael Eischer 9464c63550 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.
2023-06-08 19:18:30 +02:00

62 lines
1.1 KiB
Go

package main
import (
"testing"
"time"
"github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
)
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",
Type: "file",
Size: 14680064,
UID: 1000,
GID: 2000,
ModTime: time.Date(2020, 1, 2, 3, 4, 5, 0, time.UTC),
}
for _, c := range []struct {
path string
restic.Node
long bool
human bool
expect string
}{
{
path: testPath,
Node: node,
long: false,
human: false,
expect: testPath,
},
{
path: testPath,
Node: node,
long: true,
human: false,
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-02 03:04:05 " + testPath,
},
} {
r := formatNode(c.path, &c.Node, c.long, c.human)
rtest.Equals(t, c.expect, r)
}
}