From 78f816d190fc857c545ec6a58190670d5b02f2db Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Fri, 1 May 2015 18:27:04 +0300 Subject: [PATCH] integration: don't create factories for each test case We can do this only once. Signed-off-by: Andrey Vagin --- integration/exec_test.go | 36 +++--------------------------------- integration/init_test.go | 35 ++++++++++++++++++++++++++++++++++- integration/utils_test.go | 14 ++++---------- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/integration/exec_test.go b/integration/exec_test.go index 5ee9b9e9..c8b16687 100644 --- a/integration/exec_test.go +++ b/integration/exec_test.go @@ -204,9 +204,6 @@ func TestEnter(t *testing.T) { config := newTemplateConfig(rootfs) - factory, err := libcontainer.New(root, libcontainer.Cgroupfs) - ok(t, err) - container, err := factory.Create("test", config) ok(t, err) defer container.Destroy() @@ -294,9 +291,6 @@ func TestProcessEnv(t *testing.T) { config := newTemplateConfig(rootfs) - factory, err := libcontainer.New(root, libcontainer.Cgroupfs) - ok(t, err) - container, err := factory.Create("test", config) ok(t, err) defer container.Destroy() @@ -346,9 +340,6 @@ func TestProcessCaps(t *testing.T) { config := newTemplateConfig(rootfs) - factory, err := libcontainer.New(root, libcontainer.Cgroupfs) - ok(t, err) - container, err := factory.Create("test", config) ok(t, err) defer container.Destroy() @@ -427,15 +418,12 @@ func testFreeze(t *testing.T, systemd bool) { defer remove(rootfs) config := newTemplateConfig(rootfs) - cgm := libcontainer.Cgroupfs + f := factory if systemd { - cgm = libcontainer.SystemdCgroups + f = systemdFactory } - factory, err := libcontainer.New(root, cgm) - ok(t, err) - - container, err := factory.Create("test", config) + container, err := f.Create("test", config) ok(t, err) defer container.Destroy() @@ -539,11 +527,6 @@ func TestContainerState(t *testing.T) { {Type: configs.NEWNET}, }) - factory, err := libcontainer.New(root, libcontainer.Cgroupfs) - if err != nil { - t.Fatal(err) - } - container, err := factory.Create("test", config) if err != nil { t.Fatal(err) @@ -595,11 +578,6 @@ func TestPassExtraFiles(t *testing.T) { config := newTemplateConfig(rootfs) - factory, err := libcontainer.New(rootfs, libcontainer.Cgroupfs) - if err != nil { - t.Fatal(err) - } - container, err := factory.Create("test", config) if err != nil { t.Fatal(err) @@ -686,11 +664,6 @@ func TestMountCmds(t *testing.T) { }, }) - factory, err := libcontainer.New(root, libcontainer.Cgroupfs) - if err != nil { - t.Fatal(err) - } - container, err := factory.Create("test", config) if err != nil { t.Fatal(err) @@ -738,9 +711,6 @@ func TestSystemProperties(t *testing.T) { "kernel.shmmni": "8192", } - factory, err := libcontainer.New(root, libcontainer.Cgroupfs) - ok(t, err) - container, err := factory.Create("test", config) ok(t, err) defer container.Destroy() diff --git a/integration/init_test.go b/integration/init_test.go index 1f75ef52..b1ee20da 100644 --- a/integration/init_test.go +++ b/integration/init_test.go @@ -1,11 +1,13 @@ package integration import ( - "log" "os" "runtime" + "testing" + log "github.com/Sirupsen/logrus" "github.com/docker/libcontainer" + "github.com/docker/libcontainer/cgroups/systemd" _ "github.com/docker/libcontainer/nsenter" ) @@ -25,3 +27,34 @@ func init() { log.Fatal(err) } } + +var ( + factory libcontainer.Factory + systemdFactory libcontainer.Factory +) + +func TestMain(m *testing.M) { + var ( + err error + ret int = 0 + ) + + log.SetOutput(os.Stderr) + log.SetLevel(log.InfoLevel) + + factory, err = libcontainer.New(".", libcontainer.Cgroupfs) + if err != nil { + log.Error(err) + os.Exit(1) + } + if systemd.UseSystemd() { + systemdFactory, err = libcontainer.New(".", libcontainer.SystemdCgroups) + if err != nil { + log.Error(err) + os.Exit(1) + } + } + + ret = m.Run() + os.Exit(ret) +} diff --git a/integration/utils_test.go b/integration/utils_test.go index 263d89d3..ffd7130b 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -79,19 +79,13 @@ func copyBusybox(dest string) error { } func newContainer(config *configs.Config) (libcontainer.Container, error) { - cgm := libcontainer.Cgroupfs + f := factory + if config.Cgroups != nil && config.Cgroups.Slice == "system.slice" { - cgm = libcontainer.SystemdCgroups + f = systemdFactory } - factory, err := libcontainer.New(".", - libcontainer.InitArgs(os.Args[0], "init", "--"), - cgm, - ) - if err != nil { - return nil, err - } - return factory.Create("testCT", config) + return f.Create("testCT", config) } // runContainer runs the container with the specific config and arguments