Skip to content

Commit

Permalink
test(tools_test.go/Test_CheckRules_Glob): take into consideration RO …
Browse files Browse the repository at this point in the history
…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.

Signed-off-by: machine424 <[email protected]>
  • Loading branch information
machine424 committed Dec 20, 2024
1 parent 8311e3d commit 62b06a7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/thanos/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"os"
"path"
"testing"

"github.com/go-kit/log"
Expand Down Expand Up @@ -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)
}

0 comments on commit 62b06a7

Please sign in to comment.