internal/testutil: create, add SkipOnCentOS

CentOS 7 is showing its age and we'd rather skip some tests on it than
find out why they are flaky.

Add internal/testutil package, and move the generalized version of
SkipOnCentOS7 from libcontainer/cgroups/devices to there.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2023-10-23 11:55:12 -07:00
parent ef1166a554
commit a2f7c6add8
2 changed files with 35 additions and 24 deletions
+30
View File
@@ -0,0 +1,30 @@
package testutil
import (
"os/exec"
"strconv"
"sync"
"testing"
)
var (
centosVer string
centosVerOnce sync.Once
)
func centosVersion() string {
centosVerOnce.Do(func() {
ver, _ := exec.Command("rpm", "-q", "--qf", "%{version}", "centos-release").CombinedOutput()
centosVer = string(ver)
})
return centosVer
}
func SkipOnCentOS(t *testing.T, reason string, versions ...int) {
t.Helper()
for _, v := range versions {
if vstr := strconv.Itoa(v); centosVersion() == vstr {
t.Skip(reason + " on CentOS " + vstr)
}
}
}