From 01cd4b5f3f4ec6e45bf2d72605639c624bbc5dbf Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 11 Jul 2021 14:41:20 -0700 Subject: [PATCH] libct/int: allow subtests The t.Name() usage in libcontainer/integration prevented subtests to be used, since in such case it returns a string containing "/", and thus it can't be used to name a container. Fix this by replacing slashes with underscores where appropriate. Signed-off-by: Kir Kolyshkin (cherry picked from commit af1688a54480ff31eae683fe7466e3b90738cdb5) Signed-off-by: Kir Kolyshkin --- libcontainer/integration/template_test.go | 3 ++- libcontainer/integration/utils_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libcontainer/integration/template_test.go b/libcontainer/integration/template_test.go index c9ebff7e05f..039cd73751c 100644 --- a/libcontainer/integration/template_test.go +++ b/libcontainer/integration/template_test.go @@ -2,6 +2,7 @@ package integration import ( "strconv" + "strings" "testing" "time" @@ -215,7 +216,7 @@ func newTemplateConfig(t *testing.T, p *tParam) *configs.Config { if p.systemd { id := strconv.FormatInt(-int64(time.Now().Nanosecond()), 36) - config.Cgroups.Name = t.Name() + id + config.Cgroups.Name = strings.ReplaceAll(t.Name(), "/", "_") + id // do not change Parent (see newContainer) config.Cgroups.Parent = "system.slice" config.Cgroups.ScopePrefix = "runc-test" diff --git a/libcontainer/integration/utils_test.go b/libcontainer/integration/utils_test.go index 0ffbf179ba8..b4fa6cf655f 100644 --- a/libcontainer/integration/utils_test.go +++ b/libcontainer/integration/utils_test.go @@ -151,7 +151,7 @@ func copyBusybox(dest string) error { } func newContainer(t *testing.T, config *configs.Config) (libcontainer.Container, error) { - name := t.Name() + strconv.FormatInt(int64(time.Now().Nanosecond()), 35) + name := strings.ReplaceAll(t.Name(), "/", "_") + strconv.FormatInt(-int64(time.Now().Nanosecond()), 35) root, err := newTestRoot() if err != nil { return nil, err