Esempio n. 1
0
func newTestEngine(t utils.Fataler, autorestart bool, root string) *engine.Engine {
	if root == "" {
		if dir, err := newTestDirectory(unitTestStoreBase); err != nil {
			t.Fatal(err)
		} else {
			root = dir
		}
	}
	os.MkdirAll(root, 0700)

	eng := engine.New()
	// Load default plugins
	builtins.Register(eng)
	// (This is manually copied and modified from main() until we have a more generic plugin system)
	job := eng.Job("initserver")
	job.Setenv("Root", root)
	job.SetenvBool("AutoRestart", autorestart)
	job.Setenv("ExecDriver", "native")
	// TestGetEnabledCors and TestOptionsRoute require EnableCors=true
	job.SetenvBool("EnableCors", true)
	if err := job.Run(); err != nil {
		t.Fatal(err)
	}
	return eng
}
Esempio n. 2
0
func getContainer(eng *engine.Engine, id string, t utils.Fataler) *docker.Container {
	runtime := mkRuntimeFromEngine(eng, t)
	c := runtime.Get(id)
	if c == nil {
		t.Fatal(fmt.Errorf("No such container: %s", id))
	}
	return c
}
Esempio n. 3
0
func getContainer(eng *engine.Engine, id string, t utils.Fataler) *daemon.Container {
	daemon := mkDaemonFromEngine(eng, t)
	c := daemon.Get(id)
	if c == nil {
		t.Fatal(fmt.Errorf("No such container: %s", id))
	}
	return c
}
Esempio n. 4
0
func createNamedTestContainer(eng *engine.Engine, config *docker.Config, f utils.Fataler, name string) (shortId string) {
	job := eng.Job("create", name)
	if err := job.ImportEnv(config); err != nil {
		f.Fatal(err)
	}
	job.Stdout.AddString(&shortId)
	if err := job.Run(); err != nil {
		f.Fatal(err)
	}
	return
}
Esempio n. 5
0
func createNamedTestContainer(eng *engine.Engine, config *runconfig.Config, f utils.Fataler, name string) (shortId string) {
	job := eng.Job("create", name)
	if err := job.ImportEnv(config); err != nil {
		f.Fatal(err)
	}
	var outputBuffer = bytes.NewBuffer(nil)
	job.Stdout.Add(outputBuffer)
	if err := job.Run(); err != nil {
		f.Fatal(err)
	}
	return engine.Tail(outputBuffer, 1)
}
Esempio n. 6
0
func containerAttach(eng *engine.Engine, id string, t utils.Fataler) (io.WriteCloser, io.ReadCloser) {
	c := getContainer(eng, id, t)
	i, err := c.StdinPipe()
	if err != nil {
		t.Fatal(err)
	}
	o, err := c.StdoutPipe()
	if err != nil {
		t.Fatal(err)
	}
	return i, o
}
Esempio n. 7
0
func containerFileExists(eng *engine.Engine, id, dir string, t utils.Fataler) bool {
	c := getContainer(eng, id, t)
	if err := c.EnsureMounted(); err != nil {
		t.Fatal(err)
	}
	if _, err := os.Stat(path.Join(c.RootfsPath(), dir)); err != nil {
		if os.IsNotExist(err) {
			return false
		}
		t.Fatal(err)
	}
	return true
}
Esempio n. 8
0
// Create a temporary runtime suitable for unit testing.
// Call t.Fatal() at the first error.
func mkRuntime(f utils.Fataler) *docker.Runtime {
	root, err := newTestDirectory(unitTestStoreBase)
	if err != nil {
		f.Fatal(err)
	}
	config := &docker.DaemonConfig{
		Root:        root,
		AutoRestart: false,
		Mtu:         docker.DefaultNetworkMtu,
	}
	r, err := docker.NewRuntimeFromDirectory(config)
	if err != nil {
		f.Fatal(err)
	}
	return r
}
Esempio n. 9
0
// Create a temporary runtime suitable for unit testing.
// Call t.Fatal() at the first error.
func mkRuntime(f utils.Fataler) *Runtime {
	root, err := newTestDirectory(unitTestStoreBase)
	if err != nil {
		f.Fatal(err)
	}
	config := &DaemonConfig{
		Root:        root,
		AutoRestart: false,
	}
	r, err := NewRuntimeFromDirectory(config)
	if err != nil {
		f.Fatal(err)
	}
	r.UpdateCapabilities(true)
	return r
}
Esempio n. 10
0
func NewTestEngine(t utils.Fataler) *engine.Engine {
	root, err := newTestDirectory(unitTestStoreBase)
	if err != nil {
		t.Fatal(err)
	}
	eng, err := engine.New(root)
	if err != nil {
		t.Fatal(err)
	}
	// Load default plugins
	// (This is manually copied and modified from main() until we have a more generic plugin system)
	job := eng.Job("initapi")
	job.Setenv("Root", root)
	job.SetenvBool("AutoRestart", false)
	if err := job.Run(); err != nil {
		t.Fatal(err)
	}
	return eng
}
Esempio n. 11
0
func NewTestEngine(t utils.Fataler) *engine.Engine {
	root, err := newTestDirectory(unitTestStoreBase)
	if err != nil {
		t.Fatal(err)
	}
	eng, err := engine.New(root)
	if err != nil {
		t.Fatal(err)
	}
	// Load default plugins
	// (This is manually copied and modified from main() until we have a more generic plugin system)
	job := eng.Job("initserver")
	job.Setenv("Root", root)
	job.SetenvBool("AutoRestart", false)
	// TestGetEnabledCors and TestOptionsRoute require EnableCors=true
	job.SetenvBool("EnableCors", true)
	if err := job.Run(); err != nil {
		t.Fatal(err)
	}
	return eng
}
Esempio n. 12
0
func startContainer(eng *engine.Engine, id string, t utils.Fataler) {
	job := eng.Job("start", id)
	if err := job.Run(); err != nil {
		t.Fatal(err)
	}
}
Esempio n. 13
0
// assertHttpError expect the given response to have an error.
// Otherwise the it causes the test to fail.
func assertHttpError(r *httptest.ResponseRecorder, t utils.Fataler) {
	// Non-error http status are [200, 400)
	if !(r.Code < http.StatusOK || r.Code >= http.StatusBadRequest) {
		t.Fatal(fmt.Errorf("Unexpected http success code: %v", r.Code))
	}
}
Esempio n. 14
0
func containerAssertNotExists(eng *engine.Engine, id string, t utils.Fataler) {
	runtime := mkRuntimeFromEngine(eng, t)
	if c := runtime.Get(id); c != nil {
		t.Fatal(fmt.Errorf("Container %s should not exist", id))
	}
}
Esempio n. 15
0
func containerAssertNotExists(eng *engine.Engine, id string, t utils.Fataler) {
	daemon := mkDaemonFromEngine(eng, t)
	if c := daemon.Get(id); c != nil {
		t.Fatal(fmt.Errorf("Container %s should not exist", id))
	}
}
Esempio n. 16
0
func containerKill(eng *engine.Engine, id string, t utils.Fataler) {
	if err := eng.Job("kill", id).Run(); err != nil {
		t.Fatal(err)
	}
}
Esempio n. 17
0
func containerKill(eng *engine.Engine, id string, t utils.Fataler) {
	if err := getContainer(eng, id, t).Kill(); err != nil {
		t.Fatal(err)
	}
}