From 6ebf2dd235c9f05d5d0956c9e3c36740ee9cf9f5 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 8 Jun 2023 19:16:16 +0200 Subject: [PATCH] Reduce duplicate code in test for fomatNode --- cmd/restic/format_test.go | 49 +++++++++++++++------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/cmd/restic/format_test.go b/cmd/restic/format_test.go index 9708b03d8..97997945d 100644 --- a/cmd/restic/format_test.go +++ b/cmd/restic/format_test.go @@ -9,6 +9,16 @@ import ( ) func TestFormatNode(t *testing.T) { + 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 @@ -17,46 +27,25 @@ func TestFormatNode(t *testing.T) { 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), - }, + path: testPath, + Node: node, long: false, human: false, - expect: "/test/path", + expect: testPath, }, { - 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), - }, + path: testPath, + Node: node, long: true, human: false, - expect: "---------- 1000 2000 14680064 2020-01-01 22:04:05 /test/path", + expect: "---------- 1000 2000 14680064 2020-01-01 22:04:05 " + testPath, }, { - 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), - }, + path: testPath, + Node: node, long: true, human: true, - expect: "---------- 1000 2000 14.000 MiB 2020-01-01 22:04:05 /test/path", + expect: "---------- 1000 2000 14.000 MiB 2020-01-01 22:04:05 " + testPath, }, } { r := formatNode(c.path, &c.Node, c.long, c.human)