summaryrefslogtreecommitdiffhomepage
path: root/runsc/test/testutil
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2019-02-25 19:20:52 -0800
committerShentubot <shentubot@google.com>2019-02-25 19:21:47 -0800
commit52a2abfca43cffdb9cafb91a4266dacf51525470 (patch)
tree9a20ef60a4ecaf232749e5d22408c5c2d3de765f /runsc/test/testutil
parent563c9ed1d6814776aa22d3a272fe55c15143fe79 (diff)
Fix cgroup when path is relative
This can happen when 'docker run --cgroup-parent=' flag is set. PiperOrigin-RevId: 235645559 Change-Id: Ieea3ae66939abadab621053551bf7d62d412e7ee
Diffstat (limited to 'runsc/test/testutil')
-rw-r--r--runsc/test/testutil/docker.go8
-rw-r--r--runsc/test/testutil/testutil.go5
2 files changed, 6 insertions, 7 deletions
diff --git a/runsc/test/testutil/docker.go b/runsc/test/testutil/docker.go
index 5a92a5835..bce609061 100644
--- a/runsc/test/testutil/docker.go
+++ b/runsc/test/testutil/docker.go
@@ -18,7 +18,6 @@ import (
"fmt"
"io/ioutil"
"log"
- "math/rand"
"os"
"os/exec"
"path"
@@ -31,10 +30,6 @@ import (
"github.com/kr/pty"
)
-func init() {
- rand.Seed(time.Now().UnixNano())
-}
-
func getRuntime() string {
r := os.Getenv("RUNSC_RUNTIME")
if r == "" {
@@ -162,8 +157,7 @@ type Docker struct {
// MakeDocker sets up the struct for a Docker container.
// Names of containers will be unique.
func MakeDocker(namePrefix string) Docker {
- suffix := fmt.Sprintf("-%06d", rand.Int())[:7]
- return Docker{Name: namePrefix + suffix, Runtime: getRuntime()}
+ return Docker{Name: RandomName(namePrefix), Runtime: getRuntime()}
}
// Create calls 'docker create' with the arguments provided.
diff --git a/runsc/test/testutil/testutil.go b/runsc/test/testutil/testutil.go
index a84530287..79f0a8b6b 100644
--- a/runsc/test/testutil/testutil.go
+++ b/runsc/test/testutil/testutil.go
@@ -461,3 +461,8 @@ func WriteTmpFile(pattern, text string) (string, error) {
}
return file.Name(), nil
}
+
+// RandomName create a name with a 6 digit random number appended to it.
+func RandomName(prefix string) string {
+ return fmt.Sprintf("%s-%06d", prefix, rand.Int31n(1000000))
+}