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)
| ... | ... |
@@ -123,19 +123,8 @@ func init() {
|
| 123 | 123 |
} |
| 124 | 124 |
|
| 125 | 125 |
func setupBaseImage() {
|
| 126 |
- eng, err := engine.New(unitTestStoreBase) |
|
| 127 |
- if err != nil {
|
|
| 128 |
- log.Fatalf("Can't initialize engine at %s: %s", unitTestStoreBase, err)
|
|
| 129 |
- } |
|
| 130 |
- job := eng.Job("initserver")
|
|
| 131 |
- job.Setenv("Root", unitTestStoreBase)
|
|
| 132 |
- job.SetenvBool("Autorestart", false)
|
|
| 133 |
- job.Setenv("BridgeIface", unitTestNetworkBridge)
|
|
| 134 |
- if err := job.Run(); err != nil {
|
|
| 135 |
- log.Fatalf("Unable to create a runtime for tests: %s", err)
|
|
| 136 |
- } |
|
| 137 |
- |
|
| 138 |
- job = eng.Job("inspect", unitTestImageName, "image")
|
|
| 126 |
+ eng := newTestEngine(log.New(os.Stderr, "", 0), false, unitTestStoreBase) |
|
| 127 |
+ job := eng.Job("inspect", unitTestImageName, "image")
|
|
| 139 | 128 |
img, _ := job.Stdout.AddEnv() |
| 140 | 129 |
// If the unit test is not found, try to download it. |
| 141 | 130 |
if err := job.Run(); err != nil || img.Get("id") != unitTestImageID {
|
| ... | ... |
@@ -575,18 +564,7 @@ func TestRestore(t *testing.T) {
|
| 575 | 575 |
|
| 576 | 576 |
// Here are are simulating a docker restart - that is, reloading all containers |
| 577 | 577 |
// from scratch |
| 578 |
- root := eng.Root() |
|
| 579 |
- eng, err := engine.New(root) |
|
| 580 |
- if err != nil {
|
|
| 581 |
- t.Fatal(err) |
|
| 582 |
- } |
|
| 583 |
- job := eng.Job("initserver")
|
|
| 584 |
- job.Setenv("Root", eng.Root())
|
|
| 585 |
- job.SetenvBool("Autorestart", false)
|
|
| 586 |
- if err := job.Run(); err != nil {
|
|
| 587 |
- t.Fatal(err) |
|
| 588 |
- } |
|
| 589 |
- |
|
| 578 |
+ eng = newTestEngine(t, false, eng.Root()) |
|
| 590 | 579 |
runtime2 := mkRuntimeFromEngine(eng, t) |
| 591 | 580 |
if len(runtime2.List()) != 2 {
|
| 592 | 581 |
t.Errorf("Expected 2 container, %v found", len(runtime2.List()))
|
| ... | ... |
@@ -612,22 +590,14 @@ func TestRestore(t *testing.T) {
|
| 612 | 612 |
} |
| 613 | 613 |
|
| 614 | 614 |
func TestReloadContainerLinks(t *testing.T) {
|
| 615 |
- // FIXME: here we don't use NewTestEngine because it calls initserver with Autorestart=false, |
|
| 616 |
- // and we want to set it to true. |
|
| 617 | 615 |
root, err := newTestDirectory(unitTestStoreBase) |
| 618 | 616 |
if err != nil {
|
| 619 | 617 |
t.Fatal(err) |
| 620 | 618 |
} |
| 621 |
- eng, err := engine.New(root) |
|
| 622 |
- if err != nil {
|
|
| 623 |
- t.Fatal(err) |
|
| 624 |
- } |
|
| 625 |
- job := eng.Job("initserver")
|
|
| 626 |
- job.Setenv("Root", eng.Root())
|
|
| 627 |
- job.SetenvBool("Autorestart", true)
|
|
| 628 |
- if err := job.Run(); err != nil {
|
|
| 629 |
- t.Fatal(err) |
|
| 630 |
- } |
|
| 619 |
+ // FIXME: here we don't use NewTestEngine because it calls initserver with Autorestart=false, |
|
| 620 |
+ // and we want to set it to true. |
|
| 621 |
+ |
|
| 622 |
+ eng := newTestEngine(t, true, root) |
|
| 631 | 623 |
|
| 632 | 624 |
runtime1 := mkRuntimeFromEngine(eng, t) |
| 633 | 625 |
defer nuke(runtime1) |
| ... | ... |
@@ -668,17 +638,7 @@ func TestReloadContainerLinks(t *testing.T) {
|
| 668 | 668 |
|
| 669 | 669 |
// Here are are simulating a docker restart - that is, reloading all containers |
| 670 | 670 |
// from scratch |
| 671 |
- eng, err = engine.New(root) |
|
| 672 |
- if err != nil {
|
|
| 673 |
- t.Fatal(err) |
|
| 674 |
- } |
|
| 675 |
- job = eng.Job("initserver")
|
|
| 676 |
- job.Setenv("Root", eng.Root())
|
|
| 677 |
- job.SetenvBool("Autorestart", false)
|
|
| 678 |
- if err := job.Run(); err != nil {
|
|
| 679 |
- t.Fatal(err) |
|
| 680 |
- } |
|
| 681 |
- |
|
| 671 |
+ eng = newTestEngine(t, false, root) |
|
| 682 | 672 |
runtime2 := mkRuntimeFromEngine(eng, t) |
| 683 | 673 |
if len(runtime2.List()) != 2 {
|
| 684 | 674 |
t.Errorf("Expected 2 container, %v found", len(runtime2.List()))
|
| ... | ... |
@@ -2,7 +2,6 @@ package docker |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"github.com/dotcloud/docker" |
| 5 |
- "github.com/dotcloud/docker/engine" |
|
| 6 | 5 |
"github.com/dotcloud/docker/runconfig" |
| 7 | 6 |
"strings" |
| 8 | 7 |
"testing" |
| ... | ... |
@@ -258,20 +257,7 @@ func TestRestartKillWait(t *testing.T) {
|
| 258 | 258 |
t.Fatal(err) |
| 259 | 259 |
} |
| 260 | 260 |
|
| 261 |
- eng, err = engine.New(eng.Root()) |
|
| 262 |
- if err != nil {
|
|
| 263 |
- t.Fatal(err) |
|
| 264 |
- } |
|
| 265 |
- |
|
| 266 |
- job = eng.Job("initserver")
|
|
| 267 |
- job.Setenv("Root", eng.Root())
|
|
| 268 |
- job.SetenvBool("AutoRestart", false)
|
|
| 269 |
- // TestGetEnabledCors and TestOptionsRoute require EnableCors=true |
|
| 270 |
- job.SetenvBool("EnableCors", true)
|
|
| 271 |
- if err := job.Run(); err != nil {
|
|
| 272 |
- t.Fatal(err) |
|
| 273 |
- } |
|
| 274 |
- |
|
| 261 |
+ eng = newTestEngine(t, false, eng.Root()) |
|
| 275 | 262 |
srv = mkServerFromEngine(eng, t) |
| 276 | 263 |
|
| 277 | 264 |
job = srv.Eng.Job("containers")
|
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
"time" |
| 16 | 16 |
|
| 17 | 17 |
"github.com/dotcloud/docker" |
| 18 |
+ "github.com/dotcloud/docker/builtins" |
|
| 18 | 19 |
"github.com/dotcloud/docker/engine" |
| 19 | 20 |
"github.com/dotcloud/docker/runconfig" |
| 20 | 21 |
"github.com/dotcloud/docker/utils" |
| ... | ... |
@@ -27,26 +28,12 @@ import ( |
| 27 | 27 |
// Create a temporary runtime suitable for unit testing. |
| 28 | 28 |
// Call t.Fatal() at the first error. |
| 29 | 29 |
func mkRuntime(f utils.Fataler) *docker.Runtime {
|
| 30 |
- root, err := newTestDirectory(unitTestStoreBase) |
|
| 31 |
- if err != nil {
|
|
| 32 |
- f.Fatal(err) |
|
| 33 |
- } |
|
| 34 |
- config := &docker.DaemonConfig{
|
|
| 35 |
- Root: root, |
|
| 36 |
- AutoRestart: false, |
|
| 37 |
- Mtu: docker.GetDefaultNetworkMtu(), |
|
| 38 |
- } |
|
| 39 |
- |
|
| 40 |
- eng, err := engine.New(root) |
|
| 41 |
- if err != nil {
|
|
| 42 |
- f.Fatal(err) |
|
| 43 |
- } |
|
| 44 |
- |
|
| 45 |
- r, err := docker.NewRuntimeFromDirectory(config, eng) |
|
| 46 |
- if err != nil {
|
|
| 47 |
- f.Fatal(err) |
|
| 48 |
- } |
|
| 49 |
- return r |
|
| 30 |
+ eng := newTestEngine(f, false, "") |
|
| 31 |
+ return mkRuntimeFromEngine(eng, f) |
|
| 32 |
+ // FIXME: |
|
| 33 |
+ // [...] |
|
| 34 |
+ // Mtu: docker.GetDefaultNetworkMtu(), |
|
| 35 |
+ // [...] |
|
| 50 | 36 |
} |
| 51 | 37 |
|
| 52 | 38 |
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 {
|
| 185 | 185 |
return runtime |
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 |
-func NewTestEngine(t utils.Fataler) *engine.Engine {
|
|
| 189 |
- root, err := newTestDirectory(unitTestStoreBase) |
|
| 190 |
- if err != nil {
|
|
| 191 |
- t.Fatal(err) |
|
| 188 |
+func newTestEngine(t utils.Fataler, autorestart bool, root string) *engine.Engine {
|
|
| 189 |
+ if root == "" {
|
|
| 190 |
+ if dir, err := newTestDirectory(unitTestStoreBase); err != nil {
|
|
| 191 |
+ t.Fatal(err) |
|
| 192 |
+ } else {
|
|
| 193 |
+ root = dir |
|
| 194 |
+ } |
|
| 192 | 195 |
} |
| 193 | 196 |
eng, err := engine.New(root) |
| 194 | 197 |
if err != nil {
|
| 195 | 198 |
t.Fatal(err) |
| 196 | 199 |
} |
| 197 | 200 |
// Load default plugins |
| 201 |
+ builtins.Register(eng) |
|
| 198 | 202 |
// (This is manually copied and modified from main() until we have a more generic plugin system) |
| 199 | 203 |
job := eng.Job("initserver")
|
| 200 | 204 |
job.Setenv("Root", root)
|
| 201 |
- job.SetenvBool("AutoRestart", false)
|
|
| 205 |
+ job.SetenvBool("AutoRestart", autorestart)
|
|
| 202 | 206 |
// TestGetEnabledCors and TestOptionsRoute require EnableCors=true |
| 203 | 207 |
job.SetenvBool("EnableCors", true)
|
| 204 | 208 |
if err := job.Run(); err != nil {
|
| ... | ... |
@@ -207,6 +198,10 @@ func NewTestEngine(t utils.Fataler) *engine.Engine {
|
| 207 | 207 |
return eng |
| 208 | 208 |
} |
| 209 | 209 |
|
| 210 |
+func NewTestEngine(t utils.Fataler) *engine.Engine {
|
|
| 211 |
+ return newTestEngine(t, false, "") |
|
| 212 |
+} |
|
| 213 |
+ |
|
| 210 | 214 |
func newTestDirectory(templateDir string) (dir string, err error) {
|
| 211 | 215 |
return utils.TestDirectory(templateDir) |
| 212 | 216 |
} |