mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Cleanup integration tests
Refactor integration tests to remove special cases in the creation of test engines. All test engines are now created through newTestEngine. Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
919665a20a
commit
92c3927b5d
3 changed files with 29 additions and 88 deletions
|
@ -123,19 +123,8 @@ func init() {
|
|||
}
|
||||
|
||||
func setupBaseImage() {
|
||||
eng, err := engine.New(unitTestStoreBase)
|
||||
if err != nil {
|
||||
log.Fatalf("Can't initialize engine at %s: %s", unitTestStoreBase, err)
|
||||
}
|
||||
job := eng.Job("initserver")
|
||||
job.Setenv("Root", unitTestStoreBase)
|
||||
job.SetenvBool("Autorestart", false)
|
||||
job.Setenv("BridgeIface", unitTestNetworkBridge)
|
||||
if err := job.Run(); err != nil {
|
||||
log.Fatalf("Unable to create a runtime for tests: %s", err)
|
||||
}
|
||||
|
||||
job = eng.Job("inspect", unitTestImageName, "image")
|
||||
eng := newTestEngine(log.New(os.Stderr, "", 0), false, unitTestStoreBase)
|
||||
job := eng.Job("inspect", unitTestImageName, "image")
|
||||
img, _ := job.Stdout.AddEnv()
|
||||
// If the unit test is not found, try to download it.
|
||||
if err := job.Run(); err != nil || img.Get("id") != unitTestImageID {
|
||||
|
@ -575,18 +564,7 @@ func TestRestore(t *testing.T) {
|
|||
|
||||
// Here are are simulating a docker restart - that is, reloading all containers
|
||||
// from scratch
|
||||
root := eng.Root()
|
||||
eng, err := engine.New(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
job := eng.Job("initserver")
|
||||
job.Setenv("Root", eng.Root())
|
||||
job.SetenvBool("Autorestart", false)
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eng = newTestEngine(t, false, eng.Root())
|
||||
runtime2 := mkRuntimeFromEngine(eng, t)
|
||||
if len(runtime2.List()) != 2 {
|
||||
t.Errorf("Expected 2 container, %v found", len(runtime2.List()))
|
||||
|
@ -612,22 +590,14 @@ func TestRestore(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestReloadContainerLinks(t *testing.T) {
|
||||
// FIXME: here we don't use NewTestEngine because it calls initserver with Autorestart=false,
|
||||
// and we want to set it to true.
|
||||
root, err := newTestDirectory(unitTestStoreBase)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eng, err := engine.New(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
job := eng.Job("initserver")
|
||||
job.Setenv("Root", eng.Root())
|
||||
job.SetenvBool("Autorestart", true)
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// FIXME: here we don't use NewTestEngine because it calls initserver with Autorestart=false,
|
||||
// and we want to set it to true.
|
||||
|
||||
eng := newTestEngine(t, true, root)
|
||||
|
||||
runtime1 := mkRuntimeFromEngine(eng, t)
|
||||
defer nuke(runtime1)
|
||||
|
@ -668,17 +638,7 @@ func TestReloadContainerLinks(t *testing.T) {
|
|||
|
||||
// Here are are simulating a docker restart - that is, reloading all containers
|
||||
// from scratch
|
||||
eng, err = engine.New(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
job = eng.Job("initserver")
|
||||
job.Setenv("Root", eng.Root())
|
||||
job.SetenvBool("Autorestart", false)
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eng = newTestEngine(t, false, root)
|
||||
runtime2 := mkRuntimeFromEngine(eng, t)
|
||||
if len(runtime2.List()) != 2 {
|
||||
t.Errorf("Expected 2 container, %v found", len(runtime2.List()))
|
||||
|
|
|
@ -2,7 +2,6 @@ package docker
|
|||
|
||||
import (
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/engine"
|
||||
"github.com/dotcloud/docker/runconfig"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -258,20 +257,7 @@ func TestRestartKillWait(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eng, err = engine.New(eng.Root())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
job = eng.Job("initserver")
|
||||
job.Setenv("Root", eng.Root())
|
||||
job.SetenvBool("AutoRestart", false)
|
||||
// TestGetEnabledCors and TestOptionsRoute require EnableCors=true
|
||||
job.SetenvBool("EnableCors", true)
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eng = newTestEngine(t, false, eng.Root())
|
||||
srv = mkServerFromEngine(eng, t)
|
||||
|
||||
job = srv.Eng.Job("containers")
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/builtins"
|
||||
"github.com/dotcloud/docker/engine"
|
||||
"github.com/dotcloud/docker/runconfig"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
|
@ -27,26 +28,12 @@ import (
|
|||
// 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.GetDefaultNetworkMtu(),
|
||||
}
|
||||
|
||||
eng, err := engine.New(root)
|
||||
if err != nil {
|
||||
f.Fatal(err)
|
||||
}
|
||||
|
||||
r, err := docker.NewRuntimeFromDirectory(config, eng)
|
||||
if err != nil {
|
||||
f.Fatal(err)
|
||||
}
|
||||
return r
|
||||
eng := newTestEngine(f, false, "")
|
||||
return mkRuntimeFromEngine(eng, f)
|
||||
// FIXME:
|
||||
// [...]
|
||||
// Mtu: docker.GetDefaultNetworkMtu(),
|
||||
// [...]
|
||||
}
|
||||
|
||||
func createNamedTestContainer(eng *engine.Engine, config *runconfig.Config, f utils.Fataler, name string) (shortId string) {
|
||||
|
@ -185,20 +172,24 @@ func mkRuntimeFromEngine(eng *engine.Engine, t utils.Fataler) *docker.Runtime {
|
|||
return runtime
|
||||
}
|
||||
|
||||
func NewTestEngine(t utils.Fataler) *engine.Engine {
|
||||
root, err := newTestDirectory(unitTestStoreBase)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
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
|
||||
}
|
||||
}
|
||||
eng, err := engine.New(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// 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", false)
|
||||
job.SetenvBool("AutoRestart", autorestart)
|
||||
// TestGetEnabledCors and TestOptionsRoute require EnableCors=true
|
||||
job.SetenvBool("EnableCors", true)
|
||||
if err := job.Run(); err != nil {
|
||||
|
@ -207,6 +198,10 @@ func NewTestEngine(t utils.Fataler) *engine.Engine {
|
|||
return eng
|
||||
}
|
||||
|
||||
func NewTestEngine(t utils.Fataler) *engine.Engine {
|
||||
return newTestEngine(t, false, "")
|
||||
}
|
||||
|
||||
func newTestDirectory(templateDir string) (dir string, err error) {
|
||||
return utils.TestDirectory(templateDir)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue