From 3d4693b579ad90e66ea784722fa52e2004054633 Mon Sep 17 00:00:00 2001 From: machine424 Date: Fri, 20 Dec 2024 19:58:33 +0100 Subject: [PATCH] test(tools_test.go/Test_CheckRules_Glob): take into consideration RO current dirs while changing files permissions. The process may not have the needed permissions on the file (not the owner, not root or doesn't have the CAP_FOWNER capability) to chmod it. i Signed-off-by: machine424 --- cmd/thanos/tools_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/thanos/tools_test.go b/cmd/thanos/tools_test.go index 7d39abda55..3036810297 100644 --- a/cmd/thanos/tools_test.go +++ b/cmd/thanos/tools_test.go @@ -5,6 +5,7 @@ package main import ( "os" + "path" "testing" "github.com/go-kit/log" @@ -47,9 +48,12 @@ func Test_CheckRules_Glob(t *testing.T) { testutil.NotOk(t, checkRulesFiles(logger, files), "expected err for file %s", files) // Unreadble path - files = &[]string{"./testdata/rules-files/unreadable_valid.yaml"} - filename := (*files)[0] - testutil.Ok(t, os.Chmod(filename, 0000), "failed to change file permissions of %s to 0000", filename) + // Move the initial file to a temp dir and make it unreadble there, in case the process cannot chmod the file in the current dir. + filename := "./testdata/rules-files/unreadable_valid.yaml" + bytesRead, err := os.ReadFile(filename) + testutil.Ok(t, err) + filename = path.Join(t.TempDir(), "file.yaml") + testutil.Ok(t, os.WriteFile(filename, bytesRead, 0000)) + files = &[]string{filename} testutil.NotOk(t, checkRulesFiles(logger, files), "expected err for file %s", files) - testutil.Ok(t, os.Chmod(filename, 0777), "failed to change file permissions of %s to 0777", filename) }