2014-10-17 08:00:59 +08:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
2015-05-01 23:27:04 +08:00
|
|
|
"testing"
|
2014-10-17 08:00:59 +08:00
|
|
|
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
|
|
|
_ "github.com/opencontainers/runc/libcontainer/nsenter"
|
2017-07-19 22:28:59 +08:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2014-10-17 08:00:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// init runs the libcontainer initialization code because of the busybox style needs
|
|
|
|
// to work around the go runtime and the issues with forking
|
|
|
|
func init() {
|
|
|
|
if len(os.Args) < 2 || os.Args[1] != "init" {
|
|
|
|
return
|
|
|
|
}
|
2015-02-11 03:51:45 +08:00
|
|
|
runtime.GOMAXPROCS(1)
|
2014-10-17 08:00:59 +08:00
|
|
|
runtime.LockOSThread()
|
2015-02-14 07:43:14 +08:00
|
|
|
factory, err := libcontainer.New("")
|
2014-12-25 23:43:05 +08:00
|
|
|
if err != nil {
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.Fatalf("unable to initialize for container: %s", err)
|
2014-10-17 08:00:59 +08:00
|
|
|
}
|
2015-04-09 05:14:51 +08:00
|
|
|
if err := factory.StartInitialization(); err != nil {
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.Fatal(err)
|
2014-10-17 08:00:59 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-01 23:27:04 +08:00
|
|
|
|
2019-01-19 18:54:46 +08:00
|
|
|
var testRoots []string
|
2015-05-01 23:27:04 +08:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2015-05-06 21:14:04 +08:00
|
|
|
logrus.SetOutput(os.Stderr)
|
|
|
|
logrus.SetLevel(logrus.InfoLevel)
|
2015-05-01 23:27:04 +08:00
|
|
|
|
2019-01-19 18:54:46 +08:00
|
|
|
// Clean up roots after running everything.
|
|
|
|
defer func() {
|
|
|
|
for _, root := range testRoots {
|
|
|
|
os.RemoveAll(root)
|
2015-05-01 23:27:04 +08:00
|
|
|
}
|
2019-01-19 18:54:46 +08:00
|
|
|
}()
|
2015-05-01 23:27:04 +08:00
|
|
|
|
2019-01-19 18:54:46 +08:00
|
|
|
ret := m.Run()
|
2015-05-01 23:27:04 +08:00
|
|
|
os.Exit(ret)
|
|
|
|
}
|