From 70c88a95e35ab6a83545bf3c1cb652409f020bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 27 Nov 2023 12:01:44 +0700 Subject: [PATCH] Worker: fix timezone-dependent tests The tests were already made timezone-independent, but in a way that assumed the day would still be the same and only the time would be different. Now that assumption is removed as well. --- internal/worker/command_file_mgmt_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/worker/command_file_mgmt_test.go b/internal/worker/command_file_mgmt_test.go index 15cd7a0b..c0ae29a9 100644 --- a/internal/worker/command_file_mgmt_test.go +++ b/internal/worker/command_file_mgmt_test.go @@ -85,7 +85,7 @@ func TestCmdMoveDirectoryExistingDest(t *testing.T) { } // This cannot be a hard-coded string, as the test would fail in other timezones. - backupDir := destPath + "-2006-01-02_" + mtime.Local().Format("150405") + backupDir := destPath + "-" + mtime.Local().Format("2006-01-02_150405") // Just a sanity check. ts, err := timestampedPath(destPath) @@ -122,7 +122,7 @@ func TestCmdMoveDirectoryExistingDestAndBackup(t *testing.T) { fileCreateEmpty(filepath.Join(destPath, "destfile.txt")) // This cannot be a hard-coded string, as the test would fail in other timezones. - backupDir := destPath + "-2006-01-02_" + mtime.Local().Format("150405") + backupDir := destPath + "-" + mtime.Local().Format("2006-01-02_150405") ensureDirExists(backupDir) ensureDirExists(backupDir + "-046") fileCreateEmpty(filepath.Join(backupDir, "backupfile.txt")) @@ -169,7 +169,7 @@ func TestTimestampedPathFile(t *testing.T) { newpath, err := timestampedPath("somefile.txt") // This cannot be a hard-coded string, as the test would fail in other timezones. - expect := fmt.Sprintf("somefile.txt-2006-01-02_%s", mtime.Local().Format("150405")) + expect := "somefile.txt-" + mtime.Local().Format("2006-01-02_150405") assert.NoError(t, err) assert.Equal(t, expect, newpath) @@ -192,7 +192,7 @@ func TestTimestampedPathDir(t *testing.T) { newpath, err := timestampedPath("somedir") // This cannot be a hard-coded string, as the test would fail in other timezones. - expect := fmt.Sprintf("somedir-2006-01-02_%s", mtime.Local().Format("150405")) + expect := "somedir-" + mtime.Local().Format("2006-01-02_150405") assert.NoError(t, err) assert.Equal(t, expect, newpath)