diff --git a/cmd/thanos/tools_test.go b/cmd/thanos/tools_test.go index 7d39abda55..f93c3500e4 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 inaccessible there, in case the current dir is RO. + 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) }