integration: don't create factories for each test case

We can do this only once.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-05-01 18:27:04 +03:00
parent 6607689b1d
commit 78f816d190
3 changed files with 41 additions and 44 deletions

View File

@ -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()

View File

@ -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)
}

View File

@ -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