mirror of
https://github.com/restic/restic.git
synced 2024-06-28 08:00:52 +02:00
8812dcd56a
Modifies format module to add options for human readable storage size formatting, using size parsing already in ui/format. Cmd flag --human-readable added to ls and find commands. Additional option added to formatNode to support printing size in regular or new human readable format
66 lines
1.3 KiB
Go
66 lines
1.3 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) {
|
|
for _, c := range []struct {
|
|
path string
|
|
restic.Node
|
|
long bool
|
|
human bool
|
|
expect string
|
|
}{
|
|
{
|
|
path: "/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),
|
|
},
|
|
long: false,
|
|
human: false,
|
|
expect: "/test/path",
|
|
},
|
|
{
|
|
path: "/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),
|
|
},
|
|
long: true,
|
|
human: false,
|
|
expect: "---------- 1000 2000 14680064 2020-01-01 22:04:05 /test/path",
|
|
},
|
|
{
|
|
path: "/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),
|
|
},
|
|
long: true,
|
|
human: true,
|
|
expect: "---------- 1000 2000 14.000 MiB 2020-01-01 22:04:05 /test/path",
|
|
},
|
|
} {
|
|
r := formatNode(c.path, &c.Node, c.long, c.human)
|
|
rtest.Equals(t, r, c.expect)
|
|
}
|
|
}
|