From ec68b7238737ab0dda2d93f9a31688ecd31be2f6 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 15 Jan 2023 18:19:41 +0000 Subject: [PATCH] lib/file: fix error message test after go1.20 upgrade --- lib/file/mkdir_windows_test.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/file/mkdir_windows_test.go b/lib/file/mkdir_windows_test.go index 6b574b792..29849d7f7 100644 --- a/lib/file/mkdir_windows_test.go +++ b/lib/file/mkdir_windows_test.go @@ -77,23 +77,29 @@ func unusedDrive(t *testing.T) string { return string(letter) + ":" } -func checkMkdirAll(t *testing.T, path string, valid bool, errormsg string) { +func checkMkdirAll(t *testing.T, path string, valid bool, errormsgs... string) { if valid { assert.NoError(t, MkdirAll(path, 0777)) } else { err := MkdirAll(path, 0777) assert.Error(t, err) - assert.Equal(t, errormsg, err.Error()) + ok := false + for _, msg := range errormsgs { + if err.Error() == msg { + ok = true + } + } + assert.True(t, ok, err.Error()) } } -func checkMkdirAllSubdirs(t *testing.T, path string, valid bool, errormsg string) { - checkMkdirAll(t, path, valid, errormsg) - checkMkdirAll(t, path+`\`, valid, errormsg) - checkMkdirAll(t, path+`\parent`, valid, errormsg) - checkMkdirAll(t, path+`\parent\`, valid, errormsg) - checkMkdirAll(t, path+`\parent\child`, valid, errormsg) - checkMkdirAll(t, path+`\parent\child\`, valid, errormsg) +func checkMkdirAllSubdirs(t *testing.T, path string, valid bool, errormsgs... string) { + checkMkdirAll(t, path, valid, errormsgs...) + checkMkdirAll(t, path+`\`, valid, errormsgs...) + checkMkdirAll(t, path+`\parent`, valid, errormsgs...) + checkMkdirAll(t, path+`\parent\`, valid, errormsgs...) + checkMkdirAll(t, path+`\parent\child`, valid, errormsgs...) + checkMkdirAll(t, path+`\parent\child\`, valid, errormsgs...) } // Testing paths on existing drive @@ -143,6 +149,9 @@ func TestMkdirAllOnUnusedNetworkHost(t *testing.T) { errormsg := fmt.Sprintf("mkdir %s\\: The format of the specified network name is invalid.", path) checkMkdirAllSubdirs(t, path, false, errormsg) path = `\\?\UNC\0.0.0.0\share` - errormsg = `mkdir \\?\UNC\0.0.0.0: The specified path is invalid.` - checkMkdirAllSubdirs(t, path, false, errormsg) + checkMkdirAllSubdirs(t, path, false, + `mkdir \\?\UNC\0.0.0.0: The specified path is invalid.`, // pre go1.20 + `mkdir \\?\UNC\0.0.0.0\share\: The format of the specified network name is invalid.`, + ) + }