tests: add functionality to skip a test if it's not running in CI and not with root user (#16222)
This commit is contained in:
parent
bb4880ec13
commit
629ac58763
|
@ -0,0 +1,20 @@
|
|||
package ci
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// SkipTestWithoutRootAccess will skip test t if it's not running in CI environment
|
||||
// and test is not running with Root access.
|
||||
func SkipTestWithoutRootAccess(t *testing.T) {
|
||||
ciVar := os.Getenv("CI")
|
||||
isCI, err := strconv.ParseBool(ciVar)
|
||||
isCI = isCI && err == nil
|
||||
|
||||
if !isCI && syscall.Getuid() != 0 {
|
||||
t.Skipf("Skipping test %s. To run this test, you should run it as root user", t.Name())
|
||||
}
|
||||
}
|
|
@ -161,6 +161,7 @@ func TestTaskRunner_ArtifactHook_PartialDone(t *testing.T) {
|
|||
// TestTaskRunner_ArtifactHook_ConcurrentDownloadSuccess asserts that the artifact hook
|
||||
// download multiple files concurrently. this is a successful test without any errors.
|
||||
func TestTaskRunner_ArtifactHook_ConcurrentDownloadSuccess(t *testing.T) {
|
||||
ci.SkipTestWithoutRootAccess(t)
|
||||
t.Parallel()
|
||||
|
||||
me := &mockEmitter{}
|
||||
|
|
|
@ -1720,6 +1720,7 @@ func TestTaskRunner_DeriveToken_Unrecoverable(t *testing.T) {
|
|||
// TestTaskRunner_Download_RawExec asserts that downloaded artifacts may be
|
||||
// executed in a driver without filesystem isolation.
|
||||
func TestTaskRunner_Download_RawExec(t *testing.T) {
|
||||
ci.SkipTestWithoutRootAccess(t)
|
||||
ci.Parallel(t)
|
||||
|
||||
ts := httptest.NewServer(http.FileServer(http.Dir(filepath.Dir("."))))
|
||||
|
|
|
@ -88,6 +88,7 @@ func TestExecDriver_StartWaitStop(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExec_ExecTaskStreaming(t *testing.T) {
|
||||
ci.SkipTestWithoutRootAccess(t)
|
||||
ci.Parallel(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
|
Loading…
Reference in New Issue