Shaman: fail unit test when running as root user (linux) #104234
@ -6,6 +6,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
@ -189,20 +190,26 @@ func TestCheckSharedStoragePath(t *testing.T) {
|
|||||||
// that seems consistent.
|
// that seems consistent.
|
||||||
// FIXME: find another way to test with unwritable directories on Windows.
|
// FIXME: find another way to test with unwritable directories on Windows.
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
parentPath := filepath.Join(mf.tempdir, "deep")
|
currentUser, err := user.Current()
|
||||||
testPath := filepath.Join(parentPath, "nesting")
|
|
||||||
if err := os.Mkdir(parentPath, fs.ModePerm); !assert.NoError(t, err) {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
} else if currentUser.Username != "root" {
|
||||||
|
parentPath := filepath.Join(mf.tempdir, "deep")
|
||||||
|
testPath := filepath.Join(parentPath, "nesting")
|
||||||
|
if err := os.Mkdir(parentPath, fs.ModePerm); !assert.NoError(t, err) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := os.Mkdir(testPath, fs.FileMode(0)); !assert.NoError(t, err) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
echoCtx := doTest(testPath)
|
||||||
|
result := api.PathCheckResult{}
|
||||||
|
getResponseJSON(t, echoCtx, http.StatusOK, &result)
|
||||||
|
assert.Equal(t, testPath, result.Path)
|
||||||
|
assert.False(t, result.IsUsable)
|
||||||
|
assert.Contains(t, result.Cause, "Unable to create a file")
|
||||||
}
|
}
|
||||||
if err := os.Mkdir(testPath, fs.FileMode(0)); !assert.NoError(t, err) {
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
echoCtx := doTest(testPath)
|
|
||||||
result := api.PathCheckResult{}
|
|
||||||
getResponseJSON(t, echoCtx, http.StatusOK, &result)
|
|
||||||
assert.Equal(t, testPath, result.Path)
|
|
||||||
assert.False(t, result.IsUsable)
|
|
||||||
assert.Contains(t, result.Cause, "Unable to create a file")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user