| ... | ... |
@@ -1,76 +1,52 @@ |
| 1 | 1 |
package docker |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "archive/tar" |
|
| 5 |
- "bufio" |
|
| 6 |
- "bytes" |
|
| 4 |
+ _ "archive/tar" |
|
| 5 |
+ _ "bufio" |
|
| 6 |
+ _ "bytes" |
|
| 7 | 7 |
"encoding/json" |
| 8 |
- "fmt" |
|
| 8 |
+ "github.com/dotcloud/docker" |
|
| 9 | 9 |
"github.com/dotcloud/docker/utils" |
| 10 | 10 |
"io" |
| 11 |
- "net" |
|
| 11 |
+ _ "net" |
|
| 12 | 12 |
"net/http" |
| 13 | 13 |
"net/http/httptest" |
| 14 |
- "os" |
|
| 15 |
- "path" |
|
| 16 |
- "strings" |
|
| 14 |
+ _ "os" |
|
| 15 |
+ _ "path" |
|
| 16 |
+ _ "strings" |
|
| 17 | 17 |
"testing" |
| 18 | 18 |
"time" |
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 |
-func TestGetBoolParam(t *testing.T) {
|
|
| 22 |
- if ret, err := getBoolParam("true"); err != nil || !ret {
|
|
| 23 |
- t.Fatalf("true -> true, nil | got %t %s", ret, err)
|
|
| 24 |
- } |
|
| 25 |
- if ret, err := getBoolParam("True"); err != nil || !ret {
|
|
| 26 |
- t.Fatalf("True -> true, nil | got %t %s", ret, err)
|
|
| 27 |
- } |
|
| 28 |
- if ret, err := getBoolParam("1"); err != nil || !ret {
|
|
| 29 |
- t.Fatalf("1 -> true, nil | got %t %s", ret, err)
|
|
| 30 |
- } |
|
| 31 |
- if ret, err := getBoolParam(""); err != nil || ret {
|
|
| 32 |
- t.Fatalf("\"\" -> false, nil | got %t %s", ret, err)
|
|
| 33 |
- } |
|
| 34 |
- if ret, err := getBoolParam("false"); err != nil || ret {
|
|
| 35 |
- t.Fatalf("false -> false, nil | got %t %s", ret, err)
|
|
| 36 |
- } |
|
| 37 |
- if ret, err := getBoolParam("0"); err != nil || ret {
|
|
| 38 |
- t.Fatalf("0 -> false, nil | got %t %s", ret, err)
|
|
| 39 |
- } |
|
| 40 |
- if ret, err := getBoolParam("faux"); err == nil || ret {
|
|
| 41 |
- t.Fatalf("faux -> false, err | got %t %s", ret, err)
|
|
| 42 |
- } |
|
| 43 |
-} |
|
| 21 |
+/* |
|
| 22 |
+func TestGetVersion(t *testing.T) {
|
|
| 23 |
+ runtime := mkRuntime() |
|
| 24 |
+ defer nuke(runtime) |
|
| 25 |
+ |
|
| 26 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 44 | 27 |
|
| 45 |
-func TesthttpError(t *testing.T) {
|
|
| 28 |
+ var err error |
|
| 46 | 29 |
r := httptest.NewRecorder() |
| 47 | 30 |
|
| 48 |
- httpError(r, fmt.Errorf("No such method"))
|
|
| 49 |
- if r.Code != http.StatusNotFound {
|
|
| 50 |
- t.Fatalf("Expected %d, got %d", http.StatusNotFound, r.Code)
|
|
| 31 |
+ // FIXME getting the version should require an actual running Server |
|
| 32 |
+ if err := getVersion(srv, docker.APIVERSION, r, nil, nil); err != nil {
|
|
| 33 |
+ t.Fatal(err) |
|
| 51 | 34 |
} |
| 52 | 35 |
|
| 53 |
- httpError(r, fmt.Errorf("This accound hasn't been activated"))
|
|
| 54 |
- if r.Code != http.StatusForbidden {
|
|
| 55 |
- t.Fatalf("Expected %d, got %d", http.StatusForbidden, r.Code)
|
|
| 36 |
+ v := &APIVersion{}
|
|
| 37 |
+ if err = json.Unmarshal(r.Body.Bytes(), v); err != nil {
|
|
| 38 |
+ t.Fatal(err) |
|
| 56 | 39 |
} |
| 57 |
- |
|
| 58 |
- httpError(r, fmt.Errorf("Some error"))
|
|
| 59 |
- if r.Code != http.StatusInternalServerError {
|
|
| 60 |
- t.Fatalf("Expected %d, got %d", http.StatusInternalServerError, r.Code)
|
|
| 40 |
+ if v.Version != VERSION {
|
|
| 41 |
+ t.Errorf("Expected version %s, %s found", VERSION, v.Version)
|
|
| 61 | 42 |
} |
| 62 | 43 |
} |
| 63 | 44 |
|
| 64 |
-func TestGetVersion(t *testing.T) {
|
|
| 65 | 45 |
var err error |
| 66 |
- runtime := mkRuntime(t) |
|
| 67 |
- defer nuke(runtime) |
|
| 68 |
- |
|
| 69 |
- srv := &Server{runtime: runtime}
|
|
| 70 |
- |
|
| 71 | 46 |
r := httptest.NewRecorder() |
| 72 | 47 |
|
| 73 |
- if err := getVersion(srv, APIVERSION, r, nil, nil); err != nil {
|
|
| 48 |
+ // FIXME getting the version should require an actual running Server |
|
| 49 |
+ if err := getVersion(&docker.Server{}, docker.APIVERSION, r, nil, nil); err != nil {
|
|
| 74 | 50 |
t.Fatal(err) |
| 75 | 51 |
} |
| 76 | 52 |
|
| ... | ... |
@@ -83,11 +59,12 @@ func TestGetVersion(t *testing.T) {
|
| 83 | 83 |
} |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 |
+ |
|
| 86 | 87 |
func TestGetInfo(t *testing.T) {
|
| 87 | 88 |
runtime := mkRuntime(t) |
| 88 | 89 |
defer nuke(runtime) |
| 89 | 90 |
|
| 90 |
- srv := &Server{runtime: runtime}
|
|
| 91 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 91 | 92 |
|
| 92 | 93 |
initialImages, err := srv.runtime.graph.Map() |
| 93 | 94 |
if err != nil {
|
| ... | ... |
@@ -96,7 +73,7 @@ func TestGetInfo(t *testing.T) {
|
| 96 | 96 |
|
| 97 | 97 |
r := httptest.NewRecorder() |
| 98 | 98 |
|
| 99 |
- if err := getInfo(srv, APIVERSION, r, nil, nil); err != nil {
|
|
| 99 |
+ if err := getInfo(srv, docker.APIVERSION, r, nil, nil); err != nil {
|
|
| 100 | 100 |
t.Fatal(err) |
| 101 | 101 |
} |
| 102 | 102 |
|
| ... | ... |
@@ -109,18 +86,25 @@ func TestGetInfo(t *testing.T) {
|
| 109 | 109 |
t.Errorf("Expected images: %d, %d found", len(initialImages), infos.Images)
|
| 110 | 110 |
} |
| 111 | 111 |
} |
| 112 |
+*/ |
|
| 112 | 113 |
|
| 113 | 114 |
func TestGetEvents(t *testing.T) {
|
| 114 |
- runtime := mkRuntime(t) |
|
| 115 |
+ eng := NewTestEngine(t) |
|
| 116 |
+ srv := mkServerFromEngine(eng, t) |
|
| 117 |
+ // FIXME: we might not need runtime, why not simply nuke |
|
| 118 |
+ // the engine? |
|
| 119 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 115 | 120 |
defer nuke(runtime) |
| 116 |
- srv := &Server{
|
|
| 117 |
- runtime: runtime, |
|
| 118 |
- events: make([]utils.JSONMessage, 0, 64), |
|
| 119 |
- listeners: make(map[string]chan utils.JSONMessage), |
|
| 120 |
- } |
|
| 121 | 121 |
|
| 122 |
- srv.LogEvent("fakeaction", "fakeid", "fakeimage")
|
|
| 123 |
- srv.LogEvent("fakeaction2", "fakeid", "fakeimage")
|
|
| 122 |
+ var events []*utils.JSONMessage |
|
| 123 |
+ for _, parts := range [][3]string{
|
|
| 124 |
+ {"fakeaction", "fakeid", "fakeimage"},
|
|
| 125 |
+ {"fakeaction2", "fakeid", "fakeimage"},
|
|
| 126 |
+ } {
|
|
| 127 |
+ action, id, from := parts[0], parts[1], parts[2] |
|
| 128 |
+ ev := srv.LogEvent(action, id, from) |
|
| 129 |
+ events = append(events, ev) |
|
| 130 |
+ } |
|
| 124 | 131 |
|
| 125 | 132 |
req, err := http.NewRequest("GET", "/events?since=1", nil)
|
| 126 | 133 |
if err != nil {
|
| ... | ... |
@@ -129,7 +113,7 @@ func TestGetEvents(t *testing.T) {
|
| 129 | 129 |
|
| 130 | 130 |
r := httptest.NewRecorder() |
| 131 | 131 |
setTimeout(t, "", 500*time.Millisecond, func() {
|
| 132 |
- if err := getEvents(srv, APIVERSION, r, req, nil); err != nil {
|
|
| 132 |
+ if err := docker.ServeRequest(srv, docker.APIVERSION, r, req); err != nil {
|
|
| 133 | 133 |
t.Fatal(err) |
| 134 | 134 |
} |
| 135 | 135 |
}) |
| ... | ... |
@@ -142,18 +126,20 @@ func TestGetEvents(t *testing.T) {
|
| 142 | 142 |
} else if err != nil {
|
| 143 | 143 |
t.Fatal(err) |
| 144 | 144 |
} |
| 145 |
- if jm != srv.events[i] {
|
|
| 145 |
+ if jm != *events[i] {
|
|
| 146 | 146 |
t.Fatalf("Event received it different than expected")
|
| 147 | 147 |
} |
| 148 | 148 |
} |
| 149 | 149 |
|
| 150 | 150 |
} |
| 151 | 151 |
|
| 152 |
+/* |
|
| 153 |
+ |
|
| 152 | 154 |
func TestGetImagesJSON(t *testing.T) {
|
| 153 | 155 |
runtime := mkRuntime(t) |
| 154 | 156 |
defer nuke(runtime) |
| 155 | 157 |
|
| 156 |
- srv := &Server{runtime: runtime}
|
|
| 158 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 157 | 159 |
|
| 158 | 160 |
// all=0 |
| 159 | 161 |
|
| ... | ... |
@@ -169,7 +155,7 @@ func TestGetImagesJSON(t *testing.T) {
|
| 169 | 169 |
|
| 170 | 170 |
r := httptest.NewRecorder() |
| 171 | 171 |
|
| 172 |
- if err := getImagesJSON(srv, APIVERSION, r, req, nil); err != nil {
|
|
| 172 |
+ if err := getImagesJSON(srv, docker.APIVERSION, r, req, nil); err != nil {
|
|
| 173 | 173 |
t.Fatal(err) |
| 174 | 174 |
} |
| 175 | 175 |
|
| ... | ... |
@@ -207,7 +193,7 @@ func TestGetImagesJSON(t *testing.T) {
|
| 207 | 207 |
t.Fatal(err) |
| 208 | 208 |
} |
| 209 | 209 |
|
| 210 |
- if err := getImagesJSON(srv, APIVERSION, r2, req2, nil); err != nil {
|
|
| 210 |
+ if err := getImagesJSON(srv, docker.APIVERSION, r2, req2, nil); err != nil {
|
|
| 211 | 211 |
t.Fatal(err) |
| 212 | 212 |
} |
| 213 | 213 |
|
| ... | ... |
@@ -239,7 +225,7 @@ func TestGetImagesJSON(t *testing.T) {
|
| 239 | 239 |
t.Fatal(err) |
| 240 | 240 |
} |
| 241 | 241 |
|
| 242 |
- if err := getImagesJSON(srv, APIVERSION, r3, req3, nil); err != nil {
|
|
| 242 |
+ if err := getImagesJSON(srv, docker.APIVERSION, r3, req3, nil); err != nil {
|
|
| 243 | 243 |
t.Fatal(err) |
| 244 | 244 |
} |
| 245 | 245 |
|
| ... | ... |
@@ -260,7 +246,7 @@ func TestGetImagesJSON(t *testing.T) {
|
| 260 | 260 |
t.Fatal(err) |
| 261 | 261 |
} |
| 262 | 262 |
|
| 263 |
- err = getImagesJSON(srv, APIVERSION, r4, req4, nil) |
|
| 263 |
+ err = getImagesJSON(srv, docker.APIVERSION, r4, req4, nil) |
|
| 264 | 264 |
if err == nil {
|
| 265 | 265 |
t.Fatalf("Error expected, received none")
|
| 266 | 266 |
} |
| ... | ... |
@@ -279,11 +265,11 @@ func TestGetImagesHistory(t *testing.T) {
|
| 279 | 279 |
runtime := mkRuntime(t) |
| 280 | 280 |
defer nuke(runtime) |
| 281 | 281 |
|
| 282 |
- srv := &Server{runtime: runtime}
|
|
| 282 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 283 | 283 |
|
| 284 | 284 |
r := httptest.NewRecorder() |
| 285 | 285 |
|
| 286 |
- if err := getImagesHistory(srv, APIVERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
|
| 286 |
+ if err := getImagesHistory(srv, docker.APIVERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
|
| 287 | 287 |
t.Fatal(err) |
| 288 | 288 |
} |
| 289 | 289 |
|
| ... | ... |
@@ -300,14 +286,14 @@ func TestGetImagesByName(t *testing.T) {
|
| 300 | 300 |
runtime := mkRuntime(t) |
| 301 | 301 |
defer nuke(runtime) |
| 302 | 302 |
|
| 303 |
- srv := &Server{runtime: runtime}
|
|
| 303 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 304 | 304 |
|
| 305 | 305 |
r := httptest.NewRecorder() |
| 306 |
- if err := getImagesByName(srv, APIVERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
|
| 306 |
+ if err := getImagesByName(srv, docker.APIVERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
|
| 307 | 307 |
t.Fatal(err) |
| 308 | 308 |
} |
| 309 | 309 |
|
| 310 |
- img := &Image{}
|
|
| 310 |
+ img := &docker.Image{}
|
|
| 311 | 311 |
if err := json.Unmarshal(r.Body.Bytes(), img); err != nil {
|
| 312 | 312 |
t.Fatal(err) |
| 313 | 313 |
} |
| ... | ... |
@@ -320,7 +306,7 @@ func TestGetContainersJSON(t *testing.T) {
|
| 320 | 320 |
runtime := mkRuntime(t) |
| 321 | 321 |
defer nuke(runtime) |
| 322 | 322 |
|
| 323 |
- srv := &Server{runtime: runtime}
|
|
| 323 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 324 | 324 |
|
| 325 | 325 |
beginLen := runtime.containers.Len() |
| 326 | 326 |
|
| ... | ... |
@@ -339,7 +325,7 @@ func TestGetContainersJSON(t *testing.T) {
|
| 339 | 339 |
} |
| 340 | 340 |
|
| 341 | 341 |
r := httptest.NewRecorder() |
| 342 |
- if err := getContainersJSON(srv, APIVERSION, r, req, nil); err != nil {
|
|
| 342 |
+ if err := getContainersJSON(srv, docker.APIVERSION, r, req, nil); err != nil {
|
|
| 343 | 343 |
t.Fatal(err) |
| 344 | 344 |
} |
| 345 | 345 |
containers := []APIContainers{}
|
| ... | ... |
@@ -358,7 +344,7 @@ func TestGetContainersExport(t *testing.T) {
|
| 358 | 358 |
runtime := mkRuntime(t) |
| 359 | 359 |
defer nuke(runtime) |
| 360 | 360 |
|
| 361 |
- srv := &Server{runtime: runtime}
|
|
| 361 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 362 | 362 |
|
| 363 | 363 |
// Create a container and remove a file |
| 364 | 364 |
container, _, err := runtime.Create( |
| ... | ... |
@@ -378,7 +364,7 @@ func TestGetContainersExport(t *testing.T) {
|
| 378 | 378 |
} |
| 379 | 379 |
|
| 380 | 380 |
r := httptest.NewRecorder() |
| 381 |
- if err = getContainersExport(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 381 |
+ if err = getContainersExport(srv, docker.APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 382 | 382 |
t.Fatal(err) |
| 383 | 383 |
} |
| 384 | 384 |
|
| ... | ... |
@@ -409,7 +395,7 @@ func TestGetContainersChanges(t *testing.T) {
|
| 409 | 409 |
runtime := mkRuntime(t) |
| 410 | 410 |
defer nuke(runtime) |
| 411 | 411 |
|
| 412 |
- srv := &Server{runtime: runtime}
|
|
| 412 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 413 | 413 |
|
| 414 | 414 |
// Create a container and remove a file |
| 415 | 415 |
container, _, err := runtime.Create( |
| ... | ... |
@@ -429,7 +415,7 @@ func TestGetContainersChanges(t *testing.T) {
|
| 429 | 429 |
} |
| 430 | 430 |
|
| 431 | 431 |
r := httptest.NewRecorder() |
| 432 |
- if err := getContainersChanges(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 432 |
+ if err := getContainersChanges(srv, docker.APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 433 | 433 |
t.Fatal(err) |
| 434 | 434 |
} |
| 435 | 435 |
changes := []Change{}
|
| ... | ... |
@@ -454,7 +440,7 @@ func TestGetContainersTop(t *testing.T) {
|
| 454 | 454 |
runtime := mkRuntime(t) |
| 455 | 455 |
defer nuke(runtime) |
| 456 | 456 |
|
| 457 |
- srv := &Server{runtime: runtime}
|
|
| 457 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 458 | 458 |
|
| 459 | 459 |
container, _, err := runtime.Create( |
| 460 | 460 |
&Config{
|
| ... | ... |
@@ -505,7 +491,7 @@ func TestGetContainersTop(t *testing.T) {
|
| 505 | 505 |
if err != nil {
|
| 506 | 506 |
t.Fatal(err) |
| 507 | 507 |
} |
| 508 |
- if err := getContainersTop(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 508 |
+ if err := getContainersTop(srv, docker.APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 509 | 509 |
t.Fatal(err) |
| 510 | 510 |
} |
| 511 | 511 |
procs := APITop{}
|
| ... | ... |
@@ -535,7 +521,7 @@ func TestGetContainersByName(t *testing.T) {
|
| 535 | 535 |
runtime := mkRuntime(t) |
| 536 | 536 |
defer nuke(runtime) |
| 537 | 537 |
|
| 538 |
- srv := &Server{runtime: runtime}
|
|
| 538 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 539 | 539 |
|
| 540 | 540 |
// Create a container and remove a file |
| 541 | 541 |
container, _, err := runtime.Create( |
| ... | ... |
@@ -551,10 +537,10 @@ func TestGetContainersByName(t *testing.T) {
|
| 551 | 551 |
defer runtime.Destroy(container) |
| 552 | 552 |
|
| 553 | 553 |
r := httptest.NewRecorder() |
| 554 |
- if err := getContainersByName(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 554 |
+ if err := getContainersByName(srv, docker.APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 555 | 555 |
t.Fatal(err) |
| 556 | 556 |
} |
| 557 |
- outContainer := &Container{}
|
|
| 557 |
+ outContainer := &docker.Container{}
|
|
| 558 | 558 |
if err := json.Unmarshal(r.Body.Bytes(), outContainer); err != nil {
|
| 559 | 559 |
t.Fatal(err) |
| 560 | 560 |
} |
| ... | ... |
@@ -567,7 +553,7 @@ func TestPostCommit(t *testing.T) {
|
| 567 | 567 |
runtime := mkRuntime(t) |
| 568 | 568 |
defer nuke(runtime) |
| 569 | 569 |
|
| 570 |
- srv := &Server{runtime: runtime}
|
|
| 570 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 571 | 571 |
|
| 572 | 572 |
// Create a container and remove a file |
| 573 | 573 |
container, _, err := runtime.Create( |
| ... | ... |
@@ -592,7 +578,7 @@ func TestPostCommit(t *testing.T) {
|
| 592 | 592 |
} |
| 593 | 593 |
|
| 594 | 594 |
r := httptest.NewRecorder() |
| 595 |
- if err := postCommit(srv, APIVERSION, r, req, nil); err != nil {
|
|
| 595 |
+ if err := postCommit(srv, docker.APIVERSION, r, req, nil); err != nil {
|
|
| 596 | 596 |
t.Fatal(err) |
| 597 | 597 |
} |
| 598 | 598 |
if r.Code != http.StatusCreated {
|
| ... | ... |
@@ -629,7 +615,7 @@ func TestPostContainersCreate(t *testing.T) {
|
| 629 | 629 |
} |
| 630 | 630 |
|
| 631 | 631 |
r := httptest.NewRecorder() |
| 632 |
- if err := postContainersCreate(srv, APIVERSION, r, req, nil); err != nil {
|
|
| 632 |
+ if err := postContainersCreate(srv, docker.APIVERSION, r, req, nil); err != nil {
|
|
| 633 | 633 |
t.Fatal(err) |
| 634 | 634 |
} |
| 635 | 635 |
if r.Code != http.StatusCreated {
|
| ... | ... |
@@ -663,7 +649,7 @@ func TestPostContainersKill(t *testing.T) {
|
| 663 | 663 |
runtime := mkRuntime(t) |
| 664 | 664 |
defer nuke(runtime) |
| 665 | 665 |
|
| 666 |
- srv := &Server{runtime: runtime}
|
|
| 666 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 667 | 667 |
|
| 668 | 668 |
container, _, err := runtime.Create( |
| 669 | 669 |
&Config{
|
| ... | ... |
@@ -690,7 +676,7 @@ func TestPostContainersKill(t *testing.T) {
|
| 690 | 690 |
} |
| 691 | 691 |
|
| 692 | 692 |
r := httptest.NewRecorder() |
| 693 |
- if err := postContainersKill(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 693 |
+ if err := postContainersKill(srv, docker.APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 694 | 694 |
t.Fatal(err) |
| 695 | 695 |
} |
| 696 | 696 |
if r.Code != http.StatusNoContent {
|
| ... | ... |
@@ -705,7 +691,7 @@ func TestPostContainersRestart(t *testing.T) {
|
| 705 | 705 |
runtime := mkRuntime(t) |
| 706 | 706 |
defer nuke(runtime) |
| 707 | 707 |
|
| 708 |
- srv := &Server{runtime: runtime}
|
|
| 708 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 709 | 709 |
|
| 710 | 710 |
container, _, err := runtime.Create( |
| 711 | 711 |
&Config{
|
| ... | ... |
@@ -736,7 +722,7 @@ func TestPostContainersRestart(t *testing.T) {
|
| 736 | 736 |
t.Fatal(err) |
| 737 | 737 |
} |
| 738 | 738 |
r := httptest.NewRecorder() |
| 739 |
- if err := postContainersRestart(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 739 |
+ if err := postContainersRestart(srv, docker.APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 740 | 740 |
t.Fatal(err) |
| 741 | 741 |
} |
| 742 | 742 |
if r.Code != http.StatusNoContent {
|
| ... | ... |
@@ -780,7 +766,7 @@ func TestPostContainersStart(t *testing.T) {
|
| 780 | 780 |
req.Header.Set("Content-Type", "application/json")
|
| 781 | 781 |
|
| 782 | 782 |
r := httptest.NewRecorder() |
| 783 |
- if err := postContainersStart(srv, APIVERSION, r, req, map[string]string{"name": id}); err != nil {
|
|
| 783 |
+ if err := postContainersStart(srv, docker.APIVERSION, r, req, map[string]string{"name": id}); err != nil {
|
|
| 784 | 784 |
t.Fatal(err) |
| 785 | 785 |
} |
| 786 | 786 |
if r.Code != http.StatusNoContent {
|
| ... | ... |
@@ -799,7 +785,7 @@ func TestPostContainersStart(t *testing.T) {
|
| 799 | 799 |
} |
| 800 | 800 |
|
| 801 | 801 |
r = httptest.NewRecorder() |
| 802 |
- if err = postContainersStart(srv, APIVERSION, r, req, map[string]string{"name": id}); err == nil {
|
|
| 802 |
+ if err = postContainersStart(srv, docker.APIVERSION, r, req, map[string]string{"name": id}); err == nil {
|
|
| 803 | 803 |
t.Fatalf("A running container should be able to be started")
|
| 804 | 804 |
} |
| 805 | 805 |
|
| ... | ... |
@@ -812,7 +798,7 @@ func TestPostContainersStop(t *testing.T) {
|
| 812 | 812 |
runtime := mkRuntime(t) |
| 813 | 813 |
defer nuke(runtime) |
| 814 | 814 |
|
| 815 |
- srv := &Server{runtime: runtime}
|
|
| 815 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 816 | 816 |
|
| 817 | 817 |
container, _, err := runtime.Create( |
| 818 | 818 |
&Config{
|
| ... | ... |
@@ -844,7 +830,7 @@ func TestPostContainersStop(t *testing.T) {
|
| 844 | 844 |
t.Fatal(err) |
| 845 | 845 |
} |
| 846 | 846 |
r := httptest.NewRecorder() |
| 847 |
- if err := postContainersStop(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 847 |
+ if err := postContainersStop(srv, docker.APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 848 | 848 |
t.Fatal(err) |
| 849 | 849 |
} |
| 850 | 850 |
if r.Code != http.StatusNoContent {
|
| ... | ... |
@@ -859,7 +845,7 @@ func TestPostContainersWait(t *testing.T) {
|
| 859 | 859 |
runtime := mkRuntime(t) |
| 860 | 860 |
defer nuke(runtime) |
| 861 | 861 |
|
| 862 |
- srv := &Server{runtime: runtime}
|
|
| 862 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 863 | 863 |
|
| 864 | 864 |
container, _, err := runtime.Create( |
| 865 | 865 |
&Config{
|
| ... | ... |
@@ -880,7 +866,7 @@ func TestPostContainersWait(t *testing.T) {
|
| 880 | 880 |
|
| 881 | 881 |
setTimeout(t, "Wait timed out", 3*time.Second, func() {
|
| 882 | 882 |
r := httptest.NewRecorder() |
| 883 |
- if err := postContainersWait(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 883 |
+ if err := postContainersWait(srv, docker.APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
|
| 884 | 884 |
t.Fatal(err) |
| 885 | 885 |
} |
| 886 | 886 |
apiWait := &APIWait{}
|
| ... | ... |
@@ -901,7 +887,7 @@ func TestPostContainersAttach(t *testing.T) {
|
| 901 | 901 |
runtime := mkRuntime(t) |
| 902 | 902 |
defer nuke(runtime) |
| 903 | 903 |
|
| 904 |
- srv := &Server{runtime: runtime}
|
|
| 904 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 905 | 905 |
|
| 906 | 906 |
container, _, err := runtime.Create( |
| 907 | 907 |
&Config{
|
| ... | ... |
@@ -946,7 +932,7 @@ func TestPostContainersAttach(t *testing.T) {
|
| 946 | 946 |
t.Fatal(err) |
| 947 | 947 |
} |
| 948 | 948 |
|
| 949 |
- if err := postContainersAttach(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 949 |
+ if err := postContainersAttach(srv, docker.APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 950 | 950 |
t.Fatal(err) |
| 951 | 951 |
} |
| 952 | 952 |
}() |
| ... | ... |
@@ -990,7 +976,7 @@ func TestPostContainersAttachStderr(t *testing.T) {
|
| 990 | 990 |
runtime := mkRuntime(t) |
| 991 | 991 |
defer nuke(runtime) |
| 992 | 992 |
|
| 993 |
- srv := &Server{runtime: runtime}
|
|
| 993 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 994 | 994 |
|
| 995 | 995 |
container, _, err := runtime.Create( |
| 996 | 996 |
&Config{
|
| ... | ... |
@@ -1035,7 +1021,7 @@ func TestPostContainersAttachStderr(t *testing.T) {
|
| 1035 | 1035 |
t.Fatal(err) |
| 1036 | 1036 |
} |
| 1037 | 1037 |
|
| 1038 |
- if err := postContainersAttach(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 1038 |
+ if err := postContainersAttach(srv, docker.APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 1039 | 1039 |
t.Fatal(err) |
| 1040 | 1040 |
} |
| 1041 | 1041 |
}() |
| ... | ... |
@@ -1082,7 +1068,7 @@ func TestDeleteContainers(t *testing.T) {
|
| 1082 | 1082 |
runtime := mkRuntime(t) |
| 1083 | 1083 |
defer nuke(runtime) |
| 1084 | 1084 |
|
| 1085 |
- srv := &Server{runtime: runtime}
|
|
| 1085 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 1086 | 1086 |
|
| 1087 | 1087 |
container, _, err := runtime.Create(&Config{
|
| 1088 | 1088 |
Image: GetTestImage(runtime).ID, |
| ... | ... |
@@ -1102,7 +1088,7 @@ func TestDeleteContainers(t *testing.T) {
|
| 1102 | 1102 |
t.Fatal(err) |
| 1103 | 1103 |
} |
| 1104 | 1104 |
r := httptest.NewRecorder() |
| 1105 |
- if err := deleteContainers(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 1105 |
+ if err := deleteContainers(srv, docker.APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 1106 | 1106 |
t.Fatal(err) |
| 1107 | 1107 |
} |
| 1108 | 1108 |
if r.Code != http.StatusNoContent {
|
| ... | ... |
@@ -1123,7 +1109,7 @@ func TestOptionsRoute(t *testing.T) {
|
| 1123 | 1123 |
defer nuke(runtime) |
| 1124 | 1124 |
|
| 1125 | 1125 |
runtime.config.EnableCors = true |
| 1126 |
- srv := &Server{runtime: runtime}
|
|
| 1126 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 1127 | 1127 |
|
| 1128 | 1128 |
r := httptest.NewRecorder() |
| 1129 | 1129 |
router, err := createRouter(srv, false) |
| ... | ... |
@@ -1147,7 +1133,7 @@ func TestGetEnabledCors(t *testing.T) {
|
| 1147 | 1147 |
defer nuke(runtime) |
| 1148 | 1148 |
|
| 1149 | 1149 |
runtime.config.EnableCors = true |
| 1150 |
- srv := &Server{runtime: runtime}
|
|
| 1150 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 1151 | 1151 |
|
| 1152 | 1152 |
r := httptest.NewRecorder() |
| 1153 | 1153 |
|
| ... | ... |
@@ -1185,7 +1171,7 @@ func TestDeleteImages(t *testing.T) {
|
| 1185 | 1185 |
runtime := mkRuntime(t) |
| 1186 | 1186 |
defer nuke(runtime) |
| 1187 | 1187 |
|
| 1188 |
- srv := &Server{runtime: runtime}
|
|
| 1188 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 1189 | 1189 |
|
| 1190 | 1190 |
initialImages, err := srv.Images(false, "") |
| 1191 | 1191 |
if err != nil {
|
| ... | ... |
@@ -1211,7 +1197,7 @@ func TestDeleteImages(t *testing.T) {
|
| 1211 | 1211 |
} |
| 1212 | 1212 |
|
| 1213 | 1213 |
r := httptest.NewRecorder() |
| 1214 |
- if err := deleteImages(srv, APIVERSION, r, req, map[string]string{"name": unitTestImageID}); err == nil {
|
|
| 1214 |
+ if err := deleteImages(srv, docker.APIVERSION, r, req, map[string]string{"name": unitTestImageID}); err == nil {
|
|
| 1215 | 1215 |
t.Fatalf("Expected conflict error, got none")
|
| 1216 | 1216 |
} |
| 1217 | 1217 |
|
| ... | ... |
@@ -1221,7 +1207,7 @@ func TestDeleteImages(t *testing.T) {
|
| 1221 | 1221 |
} |
| 1222 | 1222 |
|
| 1223 | 1223 |
r2 := httptest.NewRecorder() |
| 1224 |
- if err := deleteImages(srv, APIVERSION, r2, req2, map[string]string{"name": "test:test"}); err != nil {
|
|
| 1224 |
+ if err := deleteImages(srv, docker.APIVERSION, r2, req2, map[string]string{"name": "test:test"}); err != nil {
|
|
| 1225 | 1225 |
t.Fatal(err) |
| 1226 | 1226 |
} |
| 1227 | 1227 |
if r2.Code != http.StatusOK {
|
| ... | ... |
@@ -1243,14 +1229,6 @@ func TestDeleteImages(t *testing.T) {
|
| 1243 | 1243 |
if len(images[0].RepoTags) != len(initialImages[0].RepoTags) {
|
| 1244 | 1244 |
t.Errorf("Expected %d image, %d found", len(initialImages), len(images))
|
| 1245 | 1245 |
} |
| 1246 |
- |
|
| 1247 |
- /* if c := runtime.Get(container.Id); c != nil {
|
|
| 1248 |
- t.Fatalf("The container as not been deleted")
|
|
| 1249 |
- } |
|
| 1250 |
- |
|
| 1251 |
- if _, err := os.Stat(path.Join(container.rwPath(), "test")); err == nil {
|
|
| 1252 |
- t.Fatalf("The test file has not been deleted")
|
|
| 1253 |
- } */ |
|
| 1254 | 1246 |
} |
| 1255 | 1247 |
|
| 1256 | 1248 |
func TestJsonContentType(t *testing.T) {
|
| ... | ... |
@@ -1271,7 +1249,7 @@ func TestPostContainersCopy(t *testing.T) {
|
| 1271 | 1271 |
runtime := mkRuntime(t) |
| 1272 | 1272 |
defer nuke(runtime) |
| 1273 | 1273 |
|
| 1274 |
- srv := &Server{runtime: runtime}
|
|
| 1274 |
+ srv := &docker.Server{runtime: runtime}
|
|
| 1275 | 1275 |
|
| 1276 | 1276 |
// Create a container and remove a file |
| 1277 | 1277 |
container, _, err := runtime.Create( |
| ... | ... |
@@ -1303,7 +1281,7 @@ func TestPostContainersCopy(t *testing.T) {
|
| 1303 | 1303 |
t.Fatal(err) |
| 1304 | 1304 |
} |
| 1305 | 1305 |
req.Header.Add("Content-Type", "application/json")
|
| 1306 |
- if err = postContainersCopy(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 1306 |
+ if err = postContainersCopy(srv, docker.APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
|
| 1307 | 1307 |
t.Fatal(err) |
| 1308 | 1308 |
} |
| 1309 | 1309 |
|
| ... | ... |
@@ -1356,3 +1334,4 @@ func (t *hijackTester) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
| 1356 | 1356 |
} |
| 1357 | 1357 |
return conn, bufrw, nil |
| 1358 | 1358 |
} |
| 1359 |
+*/ |
| ... | ... |
@@ -2,7 +2,9 @@ package docker |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
+ "github.com/dotcloud/docker" |
|
| 5 | 6 |
"github.com/dotcloud/docker/archive" |
| 7 |
+ "github.com/dotcloud/docker/engine" |
|
| 6 | 8 |
"io/ioutil" |
| 7 | 9 |
"net" |
| 8 | 10 |
"net/http" |
| ... | ... |
@@ -14,7 +16,7 @@ import ( |
| 14 | 14 |
// mkTestContext generates a build context from the contents of the provided dockerfile. |
| 15 | 15 |
// This context is suitable for use as an argument to BuildFile.Build() |
| 16 | 16 |
func mkTestContext(dockerfile string, files [][2]string, t *testing.T) archive.Archive {
|
| 17 |
- context, err := mkBuildContext(dockerfile, files) |
|
| 17 |
+ context, err := docker.MkBuildContext(dockerfile, files) |
|
| 18 | 18 |
if err != nil {
|
| 19 | 19 |
t.Fatal(err) |
| 20 | 20 |
} |
| ... | ... |
@@ -228,17 +230,15 @@ func TestBuild(t *testing.T) {
|
| 228 | 228 |
} |
| 229 | 229 |
} |
| 230 | 230 |
|
| 231 |
-func buildImage(context testContextTemplate, t *testing.T, srv *Server, useCache bool) *Image {
|
|
| 232 |
- if srv == nil {
|
|
| 233 |
- runtime := mkRuntime(t) |
|
| 231 |
+func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, useCache bool) *docker.Image {
|
|
| 232 |
+ if eng == nil {
|
|
| 233 |
+ eng = NewTestEngine(t) |
|
| 234 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 235 |
+ // FIXME: we might not need runtime, why not simply nuke |
|
| 236 |
+ // the engine? |
|
| 234 | 237 |
defer nuke(runtime) |
| 235 |
- |
|
| 236 |
- srv = &Server{
|
|
| 237 |
- runtime: runtime, |
|
| 238 |
- pullingPool: make(map[string]struct{}),
|
|
| 239 |
- pushingPool: make(map[string]struct{}),
|
|
| 240 |
- } |
|
| 241 | 238 |
} |
| 239 |
+ srv := mkServerFromEngine(eng, t) |
|
| 242 | 240 |
|
| 243 | 241 |
httpServer, err := mkTestingFileServer(context.remoteFiles) |
| 244 | 242 |
if err != nil {
|
| ... | ... |
@@ -252,10 +252,17 @@ func buildImage(context testContextTemplate, t *testing.T, srv *Server, useCache |
| 252 | 252 |
} |
| 253 | 253 |
port := httpServer.URL[idx+1:] |
| 254 | 254 |
|
| 255 |
- ip := srv.runtime.networkManager.bridgeNetwork.IP |
|
| 255 |
+ iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
|
|
| 256 |
+ if iIP == nil {
|
|
| 257 |
+ t.Fatal("Legacy bridgeIP field not set in engine")
|
|
| 258 |
+ } |
|
| 259 |
+ ip, ok := iIP.(net.IP) |
|
| 260 |
+ if !ok {
|
|
| 261 |
+ panic("Legacy bridgeIP field in engine does not cast to net.IP")
|
|
| 262 |
+ } |
|
| 256 | 263 |
dockerfile := constructDockerfile(context.dockerfile, ip, port) |
| 257 | 264 |
|
| 258 |
- buildfile := NewBuildFile(srv, ioutil.Discard, false, useCache, false) |
|
| 265 |
+ buildfile := docker.NewBuildFile(srv, ioutil.Discard, false, useCache, false) |
|
| 259 | 266 |
id, err := buildfile.Build(mkTestContext(dockerfile, context.files, t)) |
| 260 | 267 |
if err != nil {
|
| 261 | 268 |
t.Fatal(err) |
| ... | ... |
@@ -368,20 +375,14 @@ func TestBuildEntrypoint(t *testing.T) {
|
| 368 | 368 |
// testing #1405 - config.Cmd does not get cleaned up if |
| 369 | 369 |
// utilizing cache |
| 370 | 370 |
func TestBuildEntrypointRunCleanup(t *testing.T) {
|
| 371 |
- runtime := mkRuntime(t) |
|
| 372 |
- defer nuke(runtime) |
|
| 373 |
- |
|
| 374 |
- srv := &Server{
|
|
| 375 |
- runtime: runtime, |
|
| 376 |
- pullingPool: make(map[string]struct{}),
|
|
| 377 |
- pushingPool: make(map[string]struct{}),
|
|
| 378 |
- } |
|
| 371 |
+ eng := NewTestEngine(t) |
|
| 372 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 379 | 373 |
|
| 380 | 374 |
img := buildImage(testContextTemplate{`
|
| 381 | 375 |
from {IMAGE}
|
| 382 | 376 |
run echo "hello" |
| 383 | 377 |
`, |
| 384 |
- nil, nil}, t, srv, true) |
|
| 378 |
+ nil, nil}, t, eng, true) |
|
| 385 | 379 |
|
| 386 | 380 |
img = buildImage(testContextTemplate{`
|
| 387 | 381 |
from {IMAGE}
|
| ... | ... |
@@ -389,7 +390,7 @@ func TestBuildEntrypointRunCleanup(t *testing.T) {
|
| 389 | 389 |
add foo /foo |
| 390 | 390 |
entrypoint ["/bin/echo"] |
| 391 | 391 |
`, |
| 392 |
- [][2]string{{"foo", "HEYO"}}, nil}, t, srv, true)
|
|
| 392 |
+ [][2]string{{"foo", "HEYO"}}, nil}, t, eng, true)
|
|
| 393 | 393 |
|
| 394 | 394 |
if len(img.Config.Cmd) != 0 {
|
| 395 | 395 |
t.Fail() |
| ... | ... |
@@ -397,14 +398,8 @@ func TestBuildEntrypointRunCleanup(t *testing.T) {
|
| 397 | 397 |
} |
| 398 | 398 |
|
| 399 | 399 |
func TestBuildImageWithCache(t *testing.T) {
|
| 400 |
- runtime := mkRuntime(t) |
|
| 401 |
- defer nuke(runtime) |
|
| 402 |
- |
|
| 403 |
- srv := &Server{
|
|
| 404 |
- runtime: runtime, |
|
| 405 |
- pullingPool: make(map[string]struct{}),
|
|
| 406 |
- pushingPool: make(map[string]struct{}),
|
|
| 407 |
- } |
|
| 400 |
+ eng := NewTestEngine(t) |
|
| 401 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 408 | 402 |
|
| 409 | 403 |
template := testContextTemplate{`
|
| 410 | 404 |
from {IMAGE}
|
| ... | ... |
@@ -412,11 +407,11 @@ func TestBuildImageWithCache(t *testing.T) {
|
| 412 | 412 |
`, |
| 413 | 413 |
nil, nil} |
| 414 | 414 |
|
| 415 |
- img := buildImage(template, t, srv, true) |
|
| 415 |
+ img := buildImage(template, t, eng, true) |
|
| 416 | 416 |
imageId := img.ID |
| 417 | 417 |
|
| 418 | 418 |
img = nil |
| 419 |
- img = buildImage(template, t, srv, true) |
|
| 419 |
+ img = buildImage(template, t, eng, true) |
|
| 420 | 420 |
|
| 421 | 421 |
if imageId != img.ID {
|
| 422 | 422 |
t.Logf("Image ids should match: %s != %s", imageId, img.ID)
|
| ... | ... |
@@ -425,14 +420,8 @@ func TestBuildImageWithCache(t *testing.T) {
|
| 425 | 425 |
} |
| 426 | 426 |
|
| 427 | 427 |
func TestBuildImageWithoutCache(t *testing.T) {
|
| 428 |
- runtime := mkRuntime(t) |
|
| 429 |
- defer nuke(runtime) |
|
| 430 |
- |
|
| 431 |
- srv := &Server{
|
|
| 432 |
- runtime: runtime, |
|
| 433 |
- pullingPool: make(map[string]struct{}),
|
|
| 434 |
- pushingPool: make(map[string]struct{}),
|
|
| 435 |
- } |
|
| 428 |
+ eng := NewTestEngine(t) |
|
| 429 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 436 | 430 |
|
| 437 | 431 |
template := testContextTemplate{`
|
| 438 | 432 |
from {IMAGE}
|
| ... | ... |
@@ -440,11 +429,11 @@ func TestBuildImageWithoutCache(t *testing.T) {
|
| 440 | 440 |
`, |
| 441 | 441 |
nil, nil} |
| 442 | 442 |
|
| 443 |
- img := buildImage(template, t, srv, true) |
|
| 443 |
+ img := buildImage(template, t, eng, true) |
|
| 444 | 444 |
imageId := img.ID |
| 445 | 445 |
|
| 446 | 446 |
img = nil |
| 447 |
- img = buildImage(template, t, srv, false) |
|
| 447 |
+ img = buildImage(template, t, eng, false) |
|
| 448 | 448 |
|
| 449 | 449 |
if imageId == img.ID {
|
| 450 | 450 |
t.Logf("Image ids should not match: %s == %s", imageId, img.ID)
|
| ... | ... |
@@ -453,14 +442,9 @@ func TestBuildImageWithoutCache(t *testing.T) {
|
| 453 | 453 |
} |
| 454 | 454 |
|
| 455 | 455 |
func TestForbiddenContextPath(t *testing.T) {
|
| 456 |
- runtime := mkRuntime(t) |
|
| 457 |
- defer nuke(runtime) |
|
| 458 |
- |
|
| 459 |
- srv := &Server{
|
|
| 460 |
- runtime: runtime, |
|
| 461 |
- pullingPool: make(map[string]struct{}),
|
|
| 462 |
- pushingPool: make(map[string]struct{}),
|
|
| 463 |
- } |
|
| 456 |
+ eng := NewTestEngine(t) |
|
| 457 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 458 |
+ srv := mkServerFromEngine(eng, t) |
|
| 464 | 459 |
|
| 465 | 460 |
context := testContextTemplate{`
|
| 466 | 461 |
from {IMAGE}
|
| ... | ... |
@@ -481,10 +465,17 @@ func TestForbiddenContextPath(t *testing.T) {
|
| 481 | 481 |
} |
| 482 | 482 |
port := httpServer.URL[idx+1:] |
| 483 | 483 |
|
| 484 |
- ip := srv.runtime.networkManager.bridgeNetwork.IP |
|
| 484 |
+ iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
|
|
| 485 |
+ if iIP == nil {
|
|
| 486 |
+ t.Fatal("Legacy bridgeIP field not set in engine")
|
|
| 487 |
+ } |
|
| 488 |
+ ip, ok := iIP.(net.IP) |
|
| 489 |
+ if !ok {
|
|
| 490 |
+ panic("Legacy bridgeIP field in engine does not cast to net.IP")
|
|
| 491 |
+ } |
|
| 485 | 492 |
dockerfile := constructDockerfile(context.dockerfile, ip, port) |
| 486 | 493 |
|
| 487 |
- buildfile := NewBuildFile(srv, ioutil.Discard, false, true, false) |
|
| 494 |
+ buildfile := docker.NewBuildFile(srv, ioutil.Discard, false, true, false) |
|
| 488 | 495 |
_, err = buildfile.Build(mkTestContext(dockerfile, context.files, t)) |
| 489 | 496 |
|
| 490 | 497 |
if err == nil {
|
| ... | ... |
@@ -499,14 +490,8 @@ func TestForbiddenContextPath(t *testing.T) {
|
| 499 | 499 |
} |
| 500 | 500 |
|
| 501 | 501 |
func TestBuildADDFileNotFound(t *testing.T) {
|
| 502 |
- runtime := mkRuntime(t) |
|
| 503 |
- defer nuke(runtime) |
|
| 504 |
- |
|
| 505 |
- srv := &Server{
|
|
| 506 |
- runtime: runtime, |
|
| 507 |
- pullingPool: make(map[string]struct{}),
|
|
| 508 |
- pushingPool: make(map[string]struct{}),
|
|
| 509 |
- } |
|
| 502 |
+ eng := NewTestEngine(t) |
|
| 503 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 510 | 504 |
|
| 511 | 505 |
context := testContextTemplate{`
|
| 512 | 506 |
from {IMAGE}
|
| ... | ... |
@@ -526,10 +511,17 @@ func TestBuildADDFileNotFound(t *testing.T) {
|
| 526 | 526 |
} |
| 527 | 527 |
port := httpServer.URL[idx+1:] |
| 528 | 528 |
|
| 529 |
- ip := srv.runtime.networkManager.bridgeNetwork.IP |
|
| 529 |
+ iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
|
|
| 530 |
+ if iIP == nil {
|
|
| 531 |
+ t.Fatal("Legacy bridgeIP field not set in engine")
|
|
| 532 |
+ } |
|
| 533 |
+ ip, ok := iIP.(net.IP) |
|
| 534 |
+ if !ok {
|
|
| 535 |
+ panic("Legacy bridgeIP field in engine does not cast to net.IP")
|
|
| 536 |
+ } |
|
| 530 | 537 |
dockerfile := constructDockerfile(context.dockerfile, ip, port) |
| 531 | 538 |
|
| 532 |
- buildfile := NewBuildFile(srv, ioutil.Discard, false, true, false) |
|
| 539 |
+ buildfile := docker.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, false, true, false) |
|
| 533 | 540 |
_, err = buildfile.Build(mkTestContext(dockerfile, context.files, t)) |
| 534 | 541 |
|
| 535 | 542 |
if err == nil {
|
| ... | ... |
@@ -544,26 +536,20 @@ func TestBuildADDFileNotFound(t *testing.T) {
|
| 544 | 544 |
} |
| 545 | 545 |
|
| 546 | 546 |
func TestBuildInheritance(t *testing.T) {
|
| 547 |
- runtime := mkRuntime(t) |
|
| 548 |
- defer nuke(runtime) |
|
| 549 |
- |
|
| 550 |
- srv := &Server{
|
|
| 551 |
- runtime: runtime, |
|
| 552 |
- pullingPool: make(map[string]struct{}),
|
|
| 553 |
- pushingPool: make(map[string]struct{}),
|
|
| 554 |
- } |
|
| 547 |
+ eng := NewTestEngine(t) |
|
| 548 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 555 | 549 |
|
| 556 | 550 |
img := buildImage(testContextTemplate{`
|
| 557 | 551 |
from {IMAGE}
|
| 558 | 552 |
expose 4243 |
| 559 | 553 |
`, |
| 560 |
- nil, nil}, t, srv, true) |
|
| 554 |
+ nil, nil}, t, eng, true) |
|
| 561 | 555 |
|
| 562 | 556 |
img2 := buildImage(testContextTemplate{fmt.Sprintf(`
|
| 563 | 557 |
from %s |
| 564 | 558 |
entrypoint ["/bin/echo"] |
| 565 | 559 |
`, img.ID), |
| 566 |
- nil, nil}, t, srv, true) |
|
| 560 |
+ nil, nil}, t, eng, true) |
|
| 567 | 561 |
|
| 568 | 562 |
// from child |
| 569 | 563 |
if img2.Config.Entrypoint[0] != "/bin/echo" {
|
| ... | ... |
@@ -3,6 +3,8 @@ package docker |
| 3 | 3 |
import ( |
| 4 | 4 |
"bufio" |
| 5 | 5 |
"fmt" |
| 6 |
+ "github.com/dotcloud/docker" |
|
| 7 |
+ "github.com/dotcloud/docker/engine" |
|
| 6 | 8 |
"github.com/dotcloud/docker/utils" |
| 7 | 9 |
"io" |
| 8 | 10 |
"io/ioutil" |
| ... | ... |
@@ -66,8 +68,8 @@ func assertPipe(input, output string, r io.Reader, w io.Writer, count int) error |
| 66 | 66 |
func TestRunHostname(t *testing.T) {
|
| 67 | 67 |
stdout, stdoutPipe := io.Pipe() |
| 68 | 68 |
|
| 69 |
- cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 70 |
- defer cleanup(globalRuntime) |
|
| 69 |
+ cli := docker.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 70 |
+ defer cleanup(globalEngine, t) |
|
| 71 | 71 |
|
| 72 | 72 |
c := make(chan struct{})
|
| 73 | 73 |
go func() {
|
| ... | ... |
@@ -111,8 +113,8 @@ func TestRunHostname(t *testing.T) {
|
| 111 | 111 |
func TestRunWorkdir(t *testing.T) {
|
| 112 | 112 |
stdout, stdoutPipe := io.Pipe() |
| 113 | 113 |
|
| 114 |
- cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 115 |
- defer cleanup(globalRuntime) |
|
| 114 |
+ cli := docker.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 115 |
+ defer cleanup(globalEngine, t) |
|
| 116 | 116 |
|
| 117 | 117 |
c := make(chan struct{})
|
| 118 | 118 |
go func() {
|
| ... | ... |
@@ -156,8 +158,8 @@ func TestRunWorkdir(t *testing.T) {
|
| 156 | 156 |
func TestRunWorkdirExists(t *testing.T) {
|
| 157 | 157 |
stdout, stdoutPipe := io.Pipe() |
| 158 | 158 |
|
| 159 |
- cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 160 |
- defer cleanup(globalRuntime) |
|
| 159 |
+ cli := docker.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 160 |
+ defer cleanup(globalEngine, t) |
|
| 161 | 161 |
|
| 162 | 162 |
c := make(chan struct{})
|
| 163 | 163 |
go func() {
|
| ... | ... |
@@ -201,8 +203,8 @@ func TestRunExit(t *testing.T) {
|
| 201 | 201 |
stdin, stdinPipe := io.Pipe() |
| 202 | 202 |
stdout, stdoutPipe := io.Pipe() |
| 203 | 203 |
|
| 204 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 205 |
- defer cleanup(globalRuntime) |
|
| 204 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 205 |
+ defer cleanup(globalEngine, t) |
|
| 206 | 206 |
|
| 207 | 207 |
c1 := make(chan struct{})
|
| 208 | 208 |
go func() {
|
| ... | ... |
@@ -254,8 +256,8 @@ func TestRunDisconnect(t *testing.T) {
|
| 254 | 254 |
stdin, stdinPipe := io.Pipe() |
| 255 | 255 |
stdout, stdoutPipe := io.Pipe() |
| 256 | 256 |
|
| 257 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 258 |
- defer cleanup(globalRuntime) |
|
| 257 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 258 |
+ defer cleanup(globalEngine, t) |
|
| 259 | 259 |
|
| 260 | 260 |
c1 := make(chan struct{})
|
| 261 | 261 |
go func() {
|
| ... | ... |
@@ -299,8 +301,8 @@ func TestRunDisconnectTty(t *testing.T) {
|
| 299 | 299 |
stdin, stdinPipe := io.Pipe() |
| 300 | 300 |
stdout, stdoutPipe := io.Pipe() |
| 301 | 301 |
|
| 302 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 303 |
- defer cleanup(globalRuntime) |
|
| 302 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 303 |
+ defer cleanup(globalEngine, t) |
|
| 304 | 304 |
|
| 305 | 305 |
c1 := make(chan struct{})
|
| 306 | 306 |
go func() {
|
| ... | ... |
@@ -356,8 +358,8 @@ func TestRunAttachStdin(t *testing.T) {
|
| 356 | 356 |
stdin, stdinPipe := io.Pipe() |
| 357 | 357 |
stdout, stdoutPipe := io.Pipe() |
| 358 | 358 |
|
| 359 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 360 |
- defer cleanup(globalRuntime) |
|
| 359 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 360 |
+ defer cleanup(globalEngine, t) |
|
| 361 | 361 |
|
| 362 | 362 |
ch := make(chan struct{})
|
| 363 | 363 |
go func() {
|
| ... | ... |
@@ -420,8 +422,8 @@ func TestRunDetach(t *testing.T) {
|
| 420 | 420 |
stdin, stdinPipe := io.Pipe() |
| 421 | 421 |
stdout, stdoutPipe := io.Pipe() |
| 422 | 422 |
|
| 423 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 424 |
- defer cleanup(globalRuntime) |
|
| 423 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 424 |
+ defer cleanup(globalEngine, t) |
|
| 425 | 425 |
|
| 426 | 426 |
ch := make(chan struct{})
|
| 427 | 427 |
go func() {
|
| ... | ... |
@@ -466,8 +468,8 @@ func TestAttachDetach(t *testing.T) {
|
| 466 | 466 |
stdin, stdinPipe := io.Pipe() |
| 467 | 467 |
stdout, stdoutPipe := io.Pipe() |
| 468 | 468 |
|
| 469 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 470 |
- defer cleanup(globalRuntime) |
|
| 469 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 470 |
+ defer cleanup(globalEngine, t) |
|
| 471 | 471 |
|
| 472 | 472 |
ch := make(chan struct{})
|
| 473 | 473 |
go func() {
|
| ... | ... |
@@ -477,7 +479,7 @@ func TestAttachDetach(t *testing.T) {
|
| 477 | 477 |
} |
| 478 | 478 |
}() |
| 479 | 479 |
|
| 480 |
- var container *Container |
|
| 480 |
+ var container *docker.Container |
|
| 481 | 481 |
|
| 482 | 482 |
setTimeout(t, "Reading container's id timed out", 10*time.Second, func() {
|
| 483 | 483 |
buf := make([]byte, 1024) |
| ... | ... |
@@ -498,7 +500,7 @@ func TestAttachDetach(t *testing.T) {
|
| 498 | 498 |
|
| 499 | 499 |
stdin, stdinPipe = io.Pipe() |
| 500 | 500 |
stdout, stdoutPipe = io.Pipe() |
| 501 |
- cli = NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 501 |
+ cli = docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 502 | 502 |
|
| 503 | 503 |
ch = make(chan struct{})
|
| 504 | 504 |
go func() {
|
| ... | ... |
@@ -546,8 +548,8 @@ func TestAttachDetachTruncatedID(t *testing.T) {
|
| 546 | 546 |
stdin, stdinPipe := io.Pipe() |
| 547 | 547 |
stdout, stdoutPipe := io.Pipe() |
| 548 | 548 |
|
| 549 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 550 |
- defer cleanup(globalRuntime) |
|
| 549 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 550 |
+ defer cleanup(globalEngine, t) |
|
| 551 | 551 |
|
| 552 | 552 |
go stdout.Read(make([]byte, 1024)) |
| 553 | 553 |
setTimeout(t, "Starting container timed out", 2*time.Second, func() {
|
| ... | ... |
@@ -560,7 +562,7 @@ func TestAttachDetachTruncatedID(t *testing.T) {
|
| 560 | 560 |
|
| 561 | 561 |
stdin, stdinPipe = io.Pipe() |
| 562 | 562 |
stdout, stdoutPipe = io.Pipe() |
| 563 |
- cli = NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 563 |
+ cli = docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 564 | 564 |
|
| 565 | 565 |
ch := make(chan struct{})
|
| 566 | 566 |
go func() {
|
| ... | ... |
@@ -608,8 +610,8 @@ func TestAttachDisconnect(t *testing.T) {
|
| 608 | 608 |
stdin, stdinPipe := io.Pipe() |
| 609 | 609 |
stdout, stdoutPipe := io.Pipe() |
| 610 | 610 |
|
| 611 |
- cli := NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 612 |
- defer cleanup(globalRuntime) |
|
| 611 |
+ cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 612 |
+ defer cleanup(globalEngine, t) |
|
| 613 | 613 |
|
| 614 | 614 |
go func() {
|
| 615 | 615 |
// Start a process in daemon mode |
| ... | ... |
@@ -677,8 +679,8 @@ func TestAttachDisconnect(t *testing.T) {
|
| 677 | 677 |
func TestRunAutoRemove(t *testing.T) {
|
| 678 | 678 |
t.Skip("Fixme. Skipping test for now, race condition")
|
| 679 | 679 |
stdout, stdoutPipe := io.Pipe() |
| 680 |
- cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 681 |
- defer cleanup(globalRuntime) |
|
| 680 |
+ cli := docker.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 681 |
+ defer cleanup(globalEngine, t) |
|
| 682 | 682 |
|
| 683 | 683 |
c := make(chan struct{})
|
| 684 | 684 |
go func() {
|
| ... | ... |
@@ -712,8 +714,8 @@ func TestRunAutoRemove(t *testing.T) {
|
| 712 | 712 |
} |
| 713 | 713 |
|
| 714 | 714 |
func TestCmdLogs(t *testing.T) {
|
| 715 |
- cli := NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 716 |
- defer cleanup(globalRuntime) |
|
| 715 |
+ cli := docker.NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 716 |
+ defer cleanup(globalEngine, t) |
|
| 717 | 717 |
|
| 718 | 718 |
if err := cli.CmdRun(unitTestImageID, "sh", "-c", "ls -l"); err != nil {
|
| 719 | 719 |
t.Fatal(err) |
| ... | ... |
@@ -730,8 +732,8 @@ func TestCmdLogs(t *testing.T) {
|
| 730 | 730 |
// Expected behaviour: using / as a bind mount source should throw an error |
| 731 | 731 |
func TestRunErrorBindMountRootSource(t *testing.T) {
|
| 732 | 732 |
|
| 733 |
- cli := NewDockerCli(nil, nil, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 734 |
- defer cleanup(globalRuntime) |
|
| 733 |
+ cli := docker.NewDockerCli(nil, nil, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 734 |
+ defer cleanup(globalEngine, t) |
|
| 735 | 735 |
|
| 736 | 736 |
c := make(chan struct{})
|
| 737 | 737 |
go func() {
|
| ... | ... |
@@ -749,8 +751,8 @@ func TestRunErrorBindMountRootSource(t *testing.T) {
|
| 749 | 749 |
// Expected behaviour: error out when attempting to bind mount non-existing source paths |
| 750 | 750 |
func TestRunErrorBindNonExistingSource(t *testing.T) {
|
| 751 | 751 |
|
| 752 |
- cli := NewDockerCli(nil, nil, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 753 |
- defer cleanup(globalRuntime) |
|
| 752 |
+ cli := docker.NewDockerCli(nil, nil, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 753 |
+ defer cleanup(globalEngine, t) |
|
| 754 | 754 |
|
| 755 | 755 |
c := make(chan struct{})
|
| 756 | 756 |
go func() {
|
| ... | ... |
@@ -768,11 +770,10 @@ func TestRunErrorBindNonExistingSource(t *testing.T) {
|
| 768 | 768 |
func TestImagesViz(t *testing.T) {
|
| 769 | 769 |
stdout, stdoutPipe := io.Pipe() |
| 770 | 770 |
|
| 771 |
- cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 772 |
- defer cleanup(globalRuntime) |
|
| 771 |
+ cli := docker.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 772 |
+ defer cleanup(globalEngine, t) |
|
| 773 | 773 |
|
| 774 |
- srv := &Server{runtime: globalRuntime}
|
|
| 775 |
- image := buildTestImages(t, srv) |
|
| 774 |
+ image := buildTestImages(t, globalEngine) |
|
| 776 | 775 |
|
| 777 | 776 |
c := make(chan struct{})
|
| 778 | 777 |
go func() {
|
| ... | ... |
@@ -819,11 +820,10 @@ func TestImagesViz(t *testing.T) {
|
| 819 | 819 |
func TestImagesTree(t *testing.T) {
|
| 820 | 820 |
stdout, stdoutPipe := io.Pipe() |
| 821 | 821 |
|
| 822 |
- cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 823 |
- defer cleanup(globalRuntime) |
|
| 822 |
+ cli := docker.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 823 |
+ defer cleanup(globalEngine, t) |
|
| 824 | 824 |
|
| 825 |
- srv := &Server{runtime: globalRuntime}
|
|
| 826 |
- image := buildTestImages(t, srv) |
|
| 825 |
+ image := buildTestImages(t, globalEngine) |
|
| 827 | 826 |
|
| 828 | 827 |
c := make(chan struct{})
|
| 829 | 828 |
go func() {
|
| ... | ... |
@@ -867,7 +867,7 @@ func TestImagesTree(t *testing.T) {
|
| 867 | 867 |
}) |
| 868 | 868 |
} |
| 869 | 869 |
|
| 870 |
-func buildTestImages(t *testing.T, srv *Server) *Image {
|
|
| 870 |
+func buildTestImages(t *testing.T, eng *engine.Engine) *docker.Image {
|
|
| 871 | 871 |
|
| 872 | 872 |
var testBuilder = testContextTemplate{
|
| 873 | 873 |
` |
| ... | ... |
@@ -880,9 +880,9 @@ run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ] |
| 880 | 880 |
nil, |
| 881 | 881 |
nil, |
| 882 | 882 |
} |
| 883 |
- image := buildImage(testBuilder, t, srv, true) |
|
| 883 |
+ image := buildImage(testBuilder, t, eng, true) |
|
| 884 | 884 |
|
| 885 |
- err := srv.ContainerTag(image.ID, "test", "latest", false) |
|
| 885 |
+ err := mkServerFromEngine(eng, t).ContainerTag(image.ID, "test", "latest", false) |
|
| 886 | 886 |
if err != nil {
|
| 887 | 887 |
t.Fatal(err) |
| 888 | 888 |
} |
| ... | ... |
@@ -902,8 +902,8 @@ func TestRunCidFile(t *testing.T) {
|
| 902 | 902 |
} |
| 903 | 903 |
tmpCidFile := path.Join(tmpDir, "cid") |
| 904 | 904 |
|
| 905 |
- cli := NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 906 |
- defer cleanup(globalRuntime) |
|
| 905 |
+ cli := docker.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr) |
|
| 906 |
+ defer cleanup(globalEngine, t) |
|
| 907 | 907 |
|
| 908 | 908 |
c := make(chan struct{})
|
| 909 | 909 |
go func() {
|
| ... | ... |
@@ -3,10 +3,10 @@ package docker |
| 3 | 3 |
import ( |
| 4 | 4 |
"bufio" |
| 5 | 5 |
"fmt" |
| 6 |
+ "github.com/dotcloud/docker" |
|
| 6 | 7 |
"github.com/dotcloud/docker/utils" |
| 7 | 8 |
"io" |
| 8 | 9 |
"io/ioutil" |
| 9 |
- "math/rand" |
|
| 10 | 10 |
"os" |
| 11 | 11 |
"path" |
| 12 | 12 |
"regexp" |
| ... | ... |
@@ -20,7 +20,7 @@ func TestIDFormat(t *testing.T) {
|
| 20 | 20 |
runtime := mkRuntime(t) |
| 21 | 21 |
defer nuke(runtime) |
| 22 | 22 |
container1, _, err := runtime.Create( |
| 23 |
- &Config{
|
|
| 23 |
+ &docker.Config{
|
|
| 24 | 24 |
Image: GetTestImage(runtime).ID, |
| 25 | 25 |
Cmd: []string{"/bin/sh", "-c", "echo hello world"},
|
| 26 | 26 |
}, |
| ... | ... |
@@ -134,7 +134,8 @@ func TestMultipleAttachRestart(t *testing.T) {
|
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 | 136 |
func TestDiff(t *testing.T) {
|
| 137 |
- runtime := mkRuntime(t) |
|
| 137 |
+ eng := NewTestEngine(t) |
|
| 138 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 138 | 139 |
defer nuke(runtime) |
| 139 | 140 |
// Create a container and remove a file |
| 140 | 141 |
container1, _ := mkContainer(runtime, []string{"_", "/bin/rm", "/etc/passwd"}, t)
|
| ... | ... |
@@ -169,11 +170,7 @@ func TestDiff(t *testing.T) {
|
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 | 171 |
// Commit the container |
| 172 |
- rwTar, err := container1.ExportRw() |
|
| 173 |
- if err != nil {
|
|
| 174 |
- t.Error(err) |
|
| 175 |
- } |
|
| 176 |
- img, err := runtime.graph.Create(rwTar, container1, "unit test commited image - diff", "", nil) |
|
| 172 |
+ img, err := runtime.Commit(container1, "", "", "unit test commited image - diff", "", nil) |
|
| 177 | 173 |
if err != nil {
|
| 178 | 174 |
t.Error(err) |
| 179 | 175 |
} |
| ... | ... |
@@ -237,11 +234,7 @@ func TestCommitAutoRun(t *testing.T) {
|
| 237 | 237 |
t.Errorf("Container shouldn't be running")
|
| 238 | 238 |
} |
| 239 | 239 |
|
| 240 |
- rwTar, err := container1.ExportRw() |
|
| 241 |
- if err != nil {
|
|
| 242 |
- t.Error(err) |
|
| 243 |
- } |
|
| 244 |
- img, err := runtime.graph.Create(rwTar, container1, "unit test commited image", "", &Config{Cmd: []string{"cat", "/world"}})
|
|
| 240 |
+ img, err := runtime.Commit(container1, "", "", "unit test commited image", "", &docker.Config{Cmd: []string{"cat", "/world"}})
|
|
| 245 | 241 |
if err != nil {
|
| 246 | 242 |
t.Error(err) |
| 247 | 243 |
} |
| ... | ... |
@@ -297,11 +290,7 @@ func TestCommitRun(t *testing.T) {
|
| 297 | 297 |
t.Errorf("Container shouldn't be running")
|
| 298 | 298 |
} |
| 299 | 299 |
|
| 300 |
- rwTar, err := container1.ExportRw() |
|
| 301 |
- if err != nil {
|
|
| 302 |
- t.Error(err) |
|
| 303 |
- } |
|
| 304 |
- img, err := runtime.graph.Create(rwTar, container1, "unit test commited image", "", nil) |
|
| 300 |
+ img, err := runtime.Commit(container1, "", "", "unit test commited image", "", nil) |
|
| 305 | 301 |
if err != nil {
|
| 306 | 302 |
t.Error(err) |
| 307 | 303 |
} |
| ... | ... |
@@ -391,7 +380,7 @@ func TestOutput(t *testing.T) {
|
| 391 | 391 |
runtime := mkRuntime(t) |
| 392 | 392 |
defer nuke(runtime) |
| 393 | 393 |
container, _, err := runtime.Create( |
| 394 |
- &Config{
|
|
| 394 |
+ &docker.Config{
|
|
| 395 | 395 |
Image: GetTestImage(runtime).ID, |
| 396 | 396 |
Cmd: []string{"echo", "-n", "foobar"},
|
| 397 | 397 |
}, |
| ... | ... |
@@ -414,7 +403,7 @@ func TestContainerNetwork(t *testing.T) {
|
| 414 | 414 |
runtime := mkRuntime(t) |
| 415 | 415 |
defer nuke(runtime) |
| 416 | 416 |
container, _, err := runtime.Create( |
| 417 |
- &Config{
|
|
| 417 |
+ &docker.Config{
|
|
| 418 | 418 |
Image: GetTestImage(runtime).ID, |
| 419 | 419 |
Cmd: []string{"ping", "-c", "1", "127.0.0.1"},
|
| 420 | 420 |
}, |
| ... | ... |
@@ -436,7 +425,7 @@ func TestKillDifferentUser(t *testing.T) {
|
| 436 | 436 |
runtime := mkRuntime(t) |
| 437 | 437 |
defer nuke(runtime) |
| 438 | 438 |
|
| 439 |
- container, _, err := runtime.Create(&Config{
|
|
| 439 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 440 | 440 |
Image: GetTestImage(runtime).ID, |
| 441 | 441 |
Cmd: []string{"cat"},
|
| 442 | 442 |
OpenStdin: true, |
| ... | ... |
@@ -448,7 +437,9 @@ func TestKillDifferentUser(t *testing.T) {
|
| 448 | 448 |
t.Fatal(err) |
| 449 | 449 |
} |
| 450 | 450 |
defer runtime.Destroy(container) |
| 451 |
- defer container.stdin.Close() |
|
| 451 |
+ // FIXME @shykes: this seems redundant, but is very old, I'm leaving it in case |
|
| 452 |
+ // there is a side effect I'm not seeing. |
|
| 453 |
+ // defer container.stdin.Close() |
|
| 452 | 454 |
|
| 453 | 455 |
if container.State.Running {
|
| 454 | 456 |
t.Errorf("Container shouldn't be running")
|
| ... | ... |
@@ -490,22 +481,35 @@ func TestKillDifferentUser(t *testing.T) {
|
| 490 | 490 |
|
| 491 | 491 |
// Test that creating a container with a volume doesn't crash. Regression test for #995. |
| 492 | 492 |
func TestCreateVolume(t *testing.T) {
|
| 493 |
- runtime := mkRuntime(t) |
|
| 493 |
+ eng := NewTestEngine(t) |
|
| 494 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 494 | 495 |
defer nuke(runtime) |
| 495 | 496 |
|
| 496 |
- config, hc, _, err := ParseRun([]string{"-v", "/var/lib/data", GetTestImage(runtime).ID, "echo", "hello", "world"}, nil)
|
|
| 497 |
+ config, hc, _, err := docker.ParseRun([]string{"-v", "/var/lib/data", unitTestImageID, "echo", "hello", "world"}, nil)
|
|
| 497 | 498 |
if err != nil {
|
| 498 | 499 |
t.Fatal(err) |
| 499 | 500 |
} |
| 500 |
- c, _, err := runtime.Create(config, "") |
|
| 501 |
- if err != nil {
|
|
| 501 |
+ jobCreate := eng.Job("create")
|
|
| 502 |
+ if err := jobCreate.ImportEnv(config); err != nil {
|
|
| 503 |
+ t.Fatal(err) |
|
| 504 |
+ } |
|
| 505 |
+ var id string |
|
| 506 |
+ jobCreate.StdoutParseString(&id) |
|
| 507 |
+ if err := jobCreate.Run(); err != nil {
|
|
| 502 | 508 |
t.Fatal(err) |
| 503 | 509 |
} |
| 504 |
- defer runtime.Destroy(c) |
|
| 505 |
- c.hostConfig = hc |
|
| 506 |
- if err := c.Start(); err != nil {
|
|
| 510 |
+ jobStart := eng.Job("start", id)
|
|
| 511 |
+ if err := jobStart.ImportEnv(hc); err != nil {
|
|
| 507 | 512 |
t.Fatal(err) |
| 508 | 513 |
} |
| 514 |
+ if err := jobStart.Run(); err != nil {
|
|
| 515 |
+ t.Fatal(err) |
|
| 516 |
+ } |
|
| 517 |
+ // FIXME: this hack can be removed once Wait is a job |
|
| 518 |
+ c := runtime.Get(id) |
|
| 519 |
+ if c == nil {
|
|
| 520 |
+ t.Fatalf("Couldn't retrieve container %s from runtime", id)
|
|
| 521 |
+ } |
|
| 509 | 522 |
c.WaitTimeout(500 * time.Millisecond) |
| 510 | 523 |
c.Wait() |
| 511 | 524 |
} |
| ... | ... |
@@ -513,7 +517,7 @@ func TestCreateVolume(t *testing.T) {
|
| 513 | 513 |
func TestKill(t *testing.T) {
|
| 514 | 514 |
runtime := mkRuntime(t) |
| 515 | 515 |
defer nuke(runtime) |
| 516 |
- container, _, err := runtime.Create(&Config{
|
|
| 516 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 517 | 517 |
Image: GetTestImage(runtime).ID, |
| 518 | 518 |
Cmd: []string{"sleep", "2"},
|
| 519 | 519 |
}, |
| ... | ... |
@@ -557,7 +561,7 @@ func TestExitCode(t *testing.T) {
|
| 557 | 557 |
runtime := mkRuntime(t) |
| 558 | 558 |
defer nuke(runtime) |
| 559 | 559 |
|
| 560 |
- trueContainer, _, err := runtime.Create(&Config{
|
|
| 560 |
+ trueContainer, _, err := runtime.Create(&docker.Config{
|
|
| 561 | 561 |
Image: GetTestImage(runtime).ID, |
| 562 | 562 |
Cmd: []string{"/bin/true", ""},
|
| 563 | 563 |
}, "") |
| ... | ... |
@@ -572,7 +576,7 @@ func TestExitCode(t *testing.T) {
|
| 572 | 572 |
t.Errorf("Unexpected exit code %d (expected 0)", trueContainer.State.ExitCode)
|
| 573 | 573 |
} |
| 574 | 574 |
|
| 575 |
- falseContainer, _, err := runtime.Create(&Config{
|
|
| 575 |
+ falseContainer, _, err := runtime.Create(&docker.Config{
|
|
| 576 | 576 |
Image: GetTestImage(runtime).ID, |
| 577 | 577 |
Cmd: []string{"/bin/false", ""},
|
| 578 | 578 |
}, "") |
| ... | ... |
@@ -591,7 +595,7 @@ func TestExitCode(t *testing.T) {
|
| 591 | 591 |
func TestRestart(t *testing.T) {
|
| 592 | 592 |
runtime := mkRuntime(t) |
| 593 | 593 |
defer nuke(runtime) |
| 594 |
- container, _, err := runtime.Create(&Config{
|
|
| 594 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 595 | 595 |
Image: GetTestImage(runtime).ID, |
| 596 | 596 |
Cmd: []string{"echo", "-n", "foobar"},
|
| 597 | 597 |
}, |
| ... | ... |
@@ -622,7 +626,7 @@ func TestRestart(t *testing.T) {
|
| 622 | 622 |
func TestRestartStdin(t *testing.T) {
|
| 623 | 623 |
runtime := mkRuntime(t) |
| 624 | 624 |
defer nuke(runtime) |
| 625 |
- container, _, err := runtime.Create(&Config{
|
|
| 625 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 626 | 626 |
Image: GetTestImage(runtime).ID, |
| 627 | 627 |
Cmd: []string{"cat"},
|
| 628 | 628 |
|
| ... | ... |
@@ -700,7 +704,7 @@ func TestUser(t *testing.T) {
|
| 700 | 700 |
defer nuke(runtime) |
| 701 | 701 |
|
| 702 | 702 |
// Default user must be root |
| 703 |
- container, _, err := runtime.Create(&Config{
|
|
| 703 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 704 | 704 |
Image: GetTestImage(runtime).ID, |
| 705 | 705 |
Cmd: []string{"id"},
|
| 706 | 706 |
}, |
| ... | ... |
@@ -719,7 +723,7 @@ func TestUser(t *testing.T) {
|
| 719 | 719 |
} |
| 720 | 720 |
|
| 721 | 721 |
// Set a username |
| 722 |
- container, _, err = runtime.Create(&Config{
|
|
| 722 |
+ container, _, err = runtime.Create(&docker.Config{
|
|
| 723 | 723 |
Image: GetTestImage(runtime).ID, |
| 724 | 724 |
Cmd: []string{"id"},
|
| 725 | 725 |
|
| ... | ... |
@@ -740,7 +744,7 @@ func TestUser(t *testing.T) {
|
| 740 | 740 |
} |
| 741 | 741 |
|
| 742 | 742 |
// Set a UID |
| 743 |
- container, _, err = runtime.Create(&Config{
|
|
| 743 |
+ container, _, err = runtime.Create(&docker.Config{
|
|
| 744 | 744 |
Image: GetTestImage(runtime).ID, |
| 745 | 745 |
Cmd: []string{"id"},
|
| 746 | 746 |
|
| ... | ... |
@@ -761,7 +765,7 @@ func TestUser(t *testing.T) {
|
| 761 | 761 |
} |
| 762 | 762 |
|
| 763 | 763 |
// Set a different user by uid |
| 764 |
- container, _, err = runtime.Create(&Config{
|
|
| 764 |
+ container, _, err = runtime.Create(&docker.Config{
|
|
| 765 | 765 |
Image: GetTestImage(runtime).ID, |
| 766 | 766 |
Cmd: []string{"id"},
|
| 767 | 767 |
|
| ... | ... |
@@ -784,7 +788,7 @@ func TestUser(t *testing.T) {
|
| 784 | 784 |
} |
| 785 | 785 |
|
| 786 | 786 |
// Set a different user by username |
| 787 |
- container, _, err = runtime.Create(&Config{
|
|
| 787 |
+ container, _, err = runtime.Create(&docker.Config{
|
|
| 788 | 788 |
Image: GetTestImage(runtime).ID, |
| 789 | 789 |
Cmd: []string{"id"},
|
| 790 | 790 |
|
| ... | ... |
@@ -805,7 +809,7 @@ func TestUser(t *testing.T) {
|
| 805 | 805 |
} |
| 806 | 806 |
|
| 807 | 807 |
// Test an wrong username |
| 808 |
- container, _, err = runtime.Create(&Config{
|
|
| 808 |
+ container, _, err = runtime.Create(&docker.Config{
|
|
| 809 | 809 |
Image: GetTestImage(runtime).ID, |
| 810 | 810 |
Cmd: []string{"id"},
|
| 811 | 811 |
|
| ... | ... |
@@ -827,7 +831,7 @@ func TestMultipleContainers(t *testing.T) {
|
| 827 | 827 |
runtime := mkRuntime(t) |
| 828 | 828 |
defer nuke(runtime) |
| 829 | 829 |
|
| 830 |
- container1, _, err := runtime.Create(&Config{
|
|
| 830 |
+ container1, _, err := runtime.Create(&docker.Config{
|
|
| 831 | 831 |
Image: GetTestImage(runtime).ID, |
| 832 | 832 |
Cmd: []string{"sleep", "2"},
|
| 833 | 833 |
}, |
| ... | ... |
@@ -838,7 +842,7 @@ func TestMultipleContainers(t *testing.T) {
|
| 838 | 838 |
} |
| 839 | 839 |
defer runtime.Destroy(container1) |
| 840 | 840 |
|
| 841 |
- container2, _, err := runtime.Create(&Config{
|
|
| 841 |
+ container2, _, err := runtime.Create(&docker.Config{
|
|
| 842 | 842 |
Image: GetTestImage(runtime).ID, |
| 843 | 843 |
Cmd: []string{"sleep", "2"},
|
| 844 | 844 |
}, |
| ... | ... |
@@ -882,7 +886,7 @@ func TestMultipleContainers(t *testing.T) {
|
| 882 | 882 |
func TestStdin(t *testing.T) {
|
| 883 | 883 |
runtime := mkRuntime(t) |
| 884 | 884 |
defer nuke(runtime) |
| 885 |
- container, _, err := runtime.Create(&Config{
|
|
| 885 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 886 | 886 |
Image: GetTestImage(runtime).ID, |
| 887 | 887 |
Cmd: []string{"cat"},
|
| 888 | 888 |
|
| ... | ... |
@@ -927,7 +931,7 @@ func TestStdin(t *testing.T) {
|
| 927 | 927 |
func TestTty(t *testing.T) {
|
| 928 | 928 |
runtime := mkRuntime(t) |
| 929 | 929 |
defer nuke(runtime) |
| 930 |
- container, _, err := runtime.Create(&Config{
|
|
| 930 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 931 | 931 |
Image: GetTestImage(runtime).ID, |
| 932 | 932 |
Cmd: []string{"cat"},
|
| 933 | 933 |
|
| ... | ... |
@@ -974,7 +978,7 @@ func TestEnv(t *testing.T) {
|
| 974 | 974 |
os.Setenv("TRICKY", "tri\ncky\n")
|
| 975 | 975 |
runtime := mkRuntime(t) |
| 976 | 976 |
defer nuke(runtime) |
| 977 |
- config, _, _, err := ParseRun([]string{"-e=FALSE=true", "-e=TRUE", "-e=TRICKY", GetTestImage(runtime).ID, "env"}, nil)
|
|
| 977 |
+ config, _, _, err := docker.ParseRun([]string{"-e=FALSE=true", "-e=TRUE", "-e=TRICKY", GetTestImage(runtime).ID, "env"}, nil)
|
|
| 978 | 978 |
if err != nil {
|
| 979 | 979 |
t.Fatal(err) |
| 980 | 980 |
} |
| ... | ... |
@@ -1028,7 +1032,7 @@ func TestEntrypoint(t *testing.T) {
|
| 1028 | 1028 |
runtime := mkRuntime(t) |
| 1029 | 1029 |
defer nuke(runtime) |
| 1030 | 1030 |
container, _, err := runtime.Create( |
| 1031 |
- &Config{
|
|
| 1031 |
+ &docker.Config{
|
|
| 1032 | 1032 |
Image: GetTestImage(runtime).ID, |
| 1033 | 1033 |
Entrypoint: []string{"/bin/echo"},
|
| 1034 | 1034 |
Cmd: []string{"-n", "foobar"},
|
| ... | ... |
@@ -1052,7 +1056,7 @@ func TestEntrypointNoCmd(t *testing.T) {
|
| 1052 | 1052 |
runtime := mkRuntime(t) |
| 1053 | 1053 |
defer nuke(runtime) |
| 1054 | 1054 |
container, _, err := runtime.Create( |
| 1055 |
- &Config{
|
|
| 1055 |
+ &docker.Config{
|
|
| 1056 | 1056 |
Image: GetTestImage(runtime).ID, |
| 1057 | 1057 |
Entrypoint: []string{"/bin/echo", "foobar"},
|
| 1058 | 1058 |
}, |
| ... | ... |
@@ -1071,96 +1075,11 @@ func TestEntrypointNoCmd(t *testing.T) {
|
| 1071 | 1071 |
} |
| 1072 | 1072 |
} |
| 1073 | 1073 |
|
| 1074 |
-func grepFile(t *testing.T, path string, pattern string) {
|
|
| 1075 |
- f, err := os.Open(path) |
|
| 1076 |
- if err != nil {
|
|
| 1077 |
- t.Fatal(err) |
|
| 1078 |
- } |
|
| 1079 |
- defer f.Close() |
|
| 1080 |
- r := bufio.NewReader(f) |
|
| 1081 |
- var ( |
|
| 1082 |
- line string |
|
| 1083 |
- ) |
|
| 1084 |
- err = nil |
|
| 1085 |
- for err == nil {
|
|
| 1086 |
- line, err = r.ReadString('\n')
|
|
| 1087 |
- if strings.Contains(line, pattern) == true {
|
|
| 1088 |
- return |
|
| 1089 |
- } |
|
| 1090 |
- } |
|
| 1091 |
- t.Fatalf("grepFile: pattern \"%s\" not found in \"%s\"", pattern, path)
|
|
| 1092 |
-} |
|
| 1093 |
- |
|
| 1094 |
-func TestLXCConfig(t *testing.T) {
|
|
| 1095 |
- runtime := mkRuntime(t) |
|
| 1096 |
- defer nuke(runtime) |
|
| 1097 |
- // Memory is allocated randomly for testing |
|
| 1098 |
- rand.Seed(time.Now().UTC().UnixNano()) |
|
| 1099 |
- memMin := 33554432 |
|
| 1100 |
- memMax := 536870912 |
|
| 1101 |
- mem := memMin + rand.Intn(memMax-memMin) |
|
| 1102 |
- // CPU shares as well |
|
| 1103 |
- cpuMin := 100 |
|
| 1104 |
- cpuMax := 10000 |
|
| 1105 |
- cpu := cpuMin + rand.Intn(cpuMax-cpuMin) |
|
| 1106 |
- container, _, err := runtime.Create(&Config{
|
|
| 1107 |
- Image: GetTestImage(runtime).ID, |
|
| 1108 |
- Cmd: []string{"/bin/true"},
|
|
| 1109 |
- |
|
| 1110 |
- Hostname: "foobar", |
|
| 1111 |
- Memory: int64(mem), |
|
| 1112 |
- CpuShares: int64(cpu), |
|
| 1113 |
- }, |
|
| 1114 |
- "", |
|
| 1115 |
- ) |
|
| 1116 |
- if err != nil {
|
|
| 1117 |
- t.Fatal(err) |
|
| 1118 |
- } |
|
| 1119 |
- defer runtime.Destroy(container) |
|
| 1120 |
- container.generateLXCConfig() |
|
| 1121 |
- grepFile(t, container.lxcConfigPath(), "lxc.utsname = foobar") |
|
| 1122 |
- grepFile(t, container.lxcConfigPath(), |
|
| 1123 |
- fmt.Sprintf("lxc.cgroup.memory.limit_in_bytes = %d", mem))
|
|
| 1124 |
- grepFile(t, container.lxcConfigPath(), |
|
| 1125 |
- fmt.Sprintf("lxc.cgroup.memory.memsw.limit_in_bytes = %d", mem*2))
|
|
| 1126 |
-} |
|
| 1127 |
- |
|
| 1128 |
-func TestCustomLxcConfig(t *testing.T) {
|
|
| 1129 |
- runtime := mkRuntime(t) |
|
| 1130 |
- defer nuke(runtime) |
|
| 1131 |
- container, _, err := runtime.Create(&Config{
|
|
| 1132 |
- Image: GetTestImage(runtime).ID, |
|
| 1133 |
- Cmd: []string{"/bin/true"},
|
|
| 1134 |
- |
|
| 1135 |
- Hostname: "foobar", |
|
| 1136 |
- }, |
|
| 1137 |
- "", |
|
| 1138 |
- ) |
|
| 1139 |
- if err != nil {
|
|
| 1140 |
- t.Fatal(err) |
|
| 1141 |
- } |
|
| 1142 |
- defer runtime.Destroy(container) |
|
| 1143 |
- container.hostConfig = &HostConfig{LxcConf: []KeyValuePair{
|
|
| 1144 |
- {
|
|
| 1145 |
- Key: "lxc.utsname", |
|
| 1146 |
- Value: "docker", |
|
| 1147 |
- }, |
|
| 1148 |
- {
|
|
| 1149 |
- Key: "lxc.cgroup.cpuset.cpus", |
|
| 1150 |
- Value: "0,1", |
|
| 1151 |
- }, |
|
| 1152 |
- }} |
|
| 1153 |
- |
|
| 1154 |
- container.generateLXCConfig() |
|
| 1155 |
- grepFile(t, container.lxcConfigPath(), "lxc.utsname = docker") |
|
| 1156 |
- grepFile(t, container.lxcConfigPath(), "lxc.cgroup.cpuset.cpus = 0,1") |
|
| 1157 |
-} |
|
| 1158 |
- |
|
| 1159 | 1074 |
func BenchmarkRunSequencial(b *testing.B) {
|
| 1160 | 1075 |
runtime := mkRuntime(b) |
| 1161 | 1076 |
defer nuke(runtime) |
| 1162 | 1077 |
for i := 0; i < b.N; i++ {
|
| 1163 |
- container, _, err := runtime.Create(&Config{
|
|
| 1078 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 1164 | 1079 |
Image: GetTestImage(runtime).ID, |
| 1165 | 1080 |
Cmd: []string{"echo", "-n", "foo"},
|
| 1166 | 1081 |
}, |
| ... | ... |
@@ -1193,7 +1112,7 @@ func BenchmarkRunParallel(b *testing.B) {
|
| 1193 | 1193 |
complete := make(chan error) |
| 1194 | 1194 |
tasks = append(tasks, complete) |
| 1195 | 1195 |
go func(i int, complete chan error) {
|
| 1196 |
- container, _, err := runtime.Create(&Config{
|
|
| 1196 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 1197 | 1197 |
Image: GetTestImage(runtime).ID, |
| 1198 | 1198 |
Cmd: []string{"echo", "-n", "foo"},
|
| 1199 | 1199 |
}, |
| ... | ... |
@@ -1261,11 +1180,7 @@ func TestCopyVolumeUidGid(t *testing.T) {
|
| 1261 | 1261 |
t.Errorf("Container shouldn't be running")
|
| 1262 | 1262 |
} |
| 1263 | 1263 |
|
| 1264 |
- rwTar, err := container1.ExportRw() |
|
| 1265 |
- if err != nil {
|
|
| 1266 |
- t.Error(err) |
|
| 1267 |
- } |
|
| 1268 |
- img, err := r.graph.Create(rwTar, container1, "unit test commited image", "", nil) |
|
| 1264 |
+ img, err := r.Commit(container1, "", "", "unit test commited image", "", nil) |
|
| 1269 | 1265 |
if err != nil {
|
| 1270 | 1266 |
t.Error(err) |
| 1271 | 1267 |
} |
| ... | ... |
@@ -1298,11 +1213,7 @@ func TestCopyVolumeContent(t *testing.T) {
|
| 1298 | 1298 |
t.Errorf("Container shouldn't be running")
|
| 1299 | 1299 |
} |
| 1300 | 1300 |
|
| 1301 |
- rwTar, err := container1.ExportRw() |
|
| 1302 |
- if err != nil {
|
|
| 1303 |
- t.Error(err) |
|
| 1304 |
- } |
|
| 1305 |
- img, err := r.graph.Create(rwTar, container1, "unit test commited image", "", nil) |
|
| 1301 |
+ img, err := r.Commit(container1, "", "", "unit test commited image", "", nil) |
|
| 1306 | 1302 |
if err != nil {
|
| 1307 | 1303 |
t.Error(err) |
| 1308 | 1304 |
} |
| ... | ... |
@@ -1344,7 +1255,7 @@ func TestFromVolumesInReadonlyMode(t *testing.T) {
|
| 1344 | 1344 |
runtime := mkRuntime(t) |
| 1345 | 1345 |
defer nuke(runtime) |
| 1346 | 1346 |
container, _, err := runtime.Create( |
| 1347 |
- &Config{
|
|
| 1347 |
+ &docker.Config{
|
|
| 1348 | 1348 |
Image: GetTestImage(runtime).ID, |
| 1349 | 1349 |
Cmd: []string{"/bin/echo", "-n", "foobar"},
|
| 1350 | 1350 |
Volumes: map[string]struct{}{"/test": {}},
|
| ... | ... |
@@ -1364,7 +1275,7 @@ func TestFromVolumesInReadonlyMode(t *testing.T) {
|
| 1364 | 1364 |
} |
| 1365 | 1365 |
|
| 1366 | 1366 |
container2, _, err := runtime.Create( |
| 1367 |
- &Config{
|
|
| 1367 |
+ &docker.Config{
|
|
| 1368 | 1368 |
Image: GetTestImage(runtime).ID, |
| 1369 | 1369 |
Cmd: []string{"/bin/echo", "-n", "foobar"},
|
| 1370 | 1370 |
VolumesFrom: container.ID + ":ro", |
| ... | ... |
@@ -1405,7 +1316,7 @@ func TestVolumesFromReadonlyMount(t *testing.T) {
|
| 1405 | 1405 |
runtime := mkRuntime(t) |
| 1406 | 1406 |
defer nuke(runtime) |
| 1407 | 1407 |
container, _, err := runtime.Create( |
| 1408 |
- &Config{
|
|
| 1408 |
+ &docker.Config{
|
|
| 1409 | 1409 |
Image: GetTestImage(runtime).ID, |
| 1410 | 1410 |
Cmd: []string{"/bin/echo", "-n", "foobar"},
|
| 1411 | 1411 |
Volumes: map[string]struct{}{"/test": {}},
|
| ... | ... |
@@ -1425,7 +1336,7 @@ func TestVolumesFromReadonlyMount(t *testing.T) {
|
| 1425 | 1425 |
} |
| 1426 | 1426 |
|
| 1427 | 1427 |
container2, _, err := runtime.Create( |
| 1428 |
- &Config{
|
|
| 1428 |
+ &docker.Config{
|
|
| 1429 | 1429 |
Image: GetTestImage(runtime).ID, |
| 1430 | 1430 |
Cmd: []string{"/bin/echo", "-n", "foobar"},
|
| 1431 | 1431 |
VolumesFrom: container.ID, |
| ... | ... |
@@ -1461,7 +1372,7 @@ func TestRestartWithVolumes(t *testing.T) {
|
| 1461 | 1461 |
runtime := mkRuntime(t) |
| 1462 | 1462 |
defer nuke(runtime) |
| 1463 | 1463 |
|
| 1464 |
- container, _, err := runtime.Create(&Config{
|
|
| 1464 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 1465 | 1465 |
Image: GetTestImage(runtime).ID, |
| 1466 | 1466 |
Cmd: []string{"echo", "-n", "foobar"},
|
| 1467 | 1467 |
Volumes: map[string]struct{}{"/test": {}},
|
| ... | ... |
@@ -1505,7 +1416,7 @@ func TestVolumesFromWithVolumes(t *testing.T) {
|
| 1505 | 1505 |
runtime := mkRuntime(t) |
| 1506 | 1506 |
defer nuke(runtime) |
| 1507 | 1507 |
|
| 1508 |
- container, _, err := runtime.Create(&Config{
|
|
| 1508 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 1509 | 1509 |
Image: GetTestImage(runtime).ID, |
| 1510 | 1510 |
Cmd: []string{"sh", "-c", "echo -n bar > /test/foo"},
|
| 1511 | 1511 |
Volumes: map[string]struct{}{"/test": {}},
|
| ... | ... |
@@ -1534,7 +1445,7 @@ func TestVolumesFromWithVolumes(t *testing.T) {
|
| 1534 | 1534 |
} |
| 1535 | 1535 |
|
| 1536 | 1536 |
container2, _, err := runtime.Create( |
| 1537 |
- &Config{
|
|
| 1537 |
+ &docker.Config{
|
|
| 1538 | 1538 |
Image: GetTestImage(runtime).ID, |
| 1539 | 1539 |
Cmd: []string{"cat", "/test/foo"},
|
| 1540 | 1540 |
VolumesFrom: container.ID, |
| ... | ... |
@@ -1568,26 +1479,42 @@ func TestVolumesFromWithVolumes(t *testing.T) {
|
| 1568 | 1568 |
} |
| 1569 | 1569 |
|
| 1570 | 1570 |
func TestOnlyLoopbackExistsWhenUsingDisableNetworkOption(t *testing.T) {
|
| 1571 |
- runtime := mkRuntime(t) |
|
| 1571 |
+ eng := NewTestEngine(t) |
|
| 1572 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 1572 | 1573 |
defer nuke(runtime) |
| 1573 | 1574 |
|
| 1574 |
- config, hc, _, err := ParseRun([]string{"-n=false", GetTestImage(runtime).ID, "ip", "addr", "show"}, nil)
|
|
| 1575 |
+ config, hc, _, err := docker.ParseRun([]string{"-n=false", GetTestImage(runtime).ID, "ip", "addr", "show"}, nil)
|
|
| 1575 | 1576 |
if err != nil {
|
| 1576 | 1577 |
t.Fatal(err) |
| 1577 | 1578 |
} |
| 1578 |
- c, _, err := runtime.Create(config, "") |
|
| 1579 |
- if err != nil {
|
|
| 1579 |
+ |
|
| 1580 |
+ jobCreate := eng.Job("create")
|
|
| 1581 |
+ if err := jobCreate.ImportEnv(config); err != nil {
|
|
| 1580 | 1582 |
t.Fatal(err) |
| 1581 | 1583 |
} |
| 1584 |
+ var id string |
|
| 1585 |
+ jobCreate.StdoutParseString(&id) |
|
| 1586 |
+ if err := jobCreate.Run(); err != nil {
|
|
| 1587 |
+ t.Fatal(err) |
|
| 1588 |
+ } |
|
| 1589 |
+ // FIXME: this hack can be removed once Wait is a job |
|
| 1590 |
+ c := runtime.Get(id) |
|
| 1591 |
+ if c == nil {
|
|
| 1592 |
+ t.Fatalf("Couldn't retrieve container %s from runtime", id)
|
|
| 1593 |
+ } |
|
| 1582 | 1594 |
stdout, err := c.StdoutPipe() |
| 1583 | 1595 |
if err != nil {
|
| 1584 | 1596 |
t.Fatal(err) |
| 1585 | 1597 |
} |
| 1586 |
- defer runtime.Destroy(c) |
|
| 1587 |
- c.hostConfig = hc |
|
| 1588 |
- if err := c.Start(); err != nil {
|
|
| 1598 |
+ |
|
| 1599 |
+ jobStart := eng.Job("start", id)
|
|
| 1600 |
+ if err := jobStart.ImportEnv(hc); err != nil {
|
|
| 1601 |
+ t.Fatal(err) |
|
| 1602 |
+ } |
|
| 1603 |
+ if err := jobStart.Run(); err != nil {
|
|
| 1589 | 1604 |
t.Fatal(err) |
| 1590 | 1605 |
} |
| 1606 |
+ |
|
| 1591 | 1607 |
c.WaitTimeout(500 * time.Millisecond) |
| 1592 | 1608 |
c.Wait() |
| 1593 | 1609 |
output, err := ioutil.ReadAll(stdout) |
| ... | ... |
@@ -1602,7 +1529,6 @@ func TestOnlyLoopbackExistsWhenUsingDisableNetworkOption(t *testing.T) {
|
| 1602 | 1602 |
if !strings.HasSuffix(interfaces[0], ": lo") {
|
| 1603 | 1603 |
t.Fatalf("Wrong interface in test container: expected [*: lo], got %s", interfaces)
|
| 1604 | 1604 |
} |
| 1605 |
- |
|
| 1606 | 1605 |
} |
| 1607 | 1606 |
|
| 1608 | 1607 |
func TestPrivilegedCanMknod(t *testing.T) {
|
| ... | ... |
@@ -1641,7 +1567,7 @@ func TestMultipleVolumesFrom(t *testing.T) {
|
| 1641 | 1641 |
runtime := mkRuntime(t) |
| 1642 | 1642 |
defer nuke(runtime) |
| 1643 | 1643 |
|
| 1644 |
- container, _, err := runtime.Create(&Config{
|
|
| 1644 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 1645 | 1645 |
Image: GetTestImage(runtime).ID, |
| 1646 | 1646 |
Cmd: []string{"sh", "-c", "echo -n bar > /test/foo"},
|
| 1647 | 1647 |
Volumes: map[string]struct{}{"/test": {}},
|
| ... | ... |
@@ -1670,7 +1596,7 @@ func TestMultipleVolumesFrom(t *testing.T) {
|
| 1670 | 1670 |
} |
| 1671 | 1671 |
|
| 1672 | 1672 |
container2, _, err := runtime.Create( |
| 1673 |
- &Config{
|
|
| 1673 |
+ &docker.Config{
|
|
| 1674 | 1674 |
Image: GetTestImage(runtime).ID, |
| 1675 | 1675 |
Cmd: []string{"sh", "-c", "echo -n bar > /other/foo"},
|
| 1676 | 1676 |
Volumes: map[string]struct{}{"/other": {}},
|
| ... | ... |
@@ -1692,7 +1618,7 @@ func TestMultipleVolumesFrom(t *testing.T) {
|
| 1692 | 1692 |
} |
| 1693 | 1693 |
|
| 1694 | 1694 |
container3, _, err := runtime.Create( |
| 1695 |
- &Config{
|
|
| 1695 |
+ &docker.Config{
|
|
| 1696 | 1696 |
Image: GetTestImage(runtime).ID, |
| 1697 | 1697 |
Cmd: []string{"/bin/echo", "-n", "foobar"},
|
| 1698 | 1698 |
VolumesFrom: strings.Join([]string{container.ID, container2.ID}, ","),
|
| ... | ... |
@@ -1720,7 +1646,7 @@ func TestRestartGhost(t *testing.T) {
|
| 1720 | 1720 |
defer nuke(runtime) |
| 1721 | 1721 |
|
| 1722 | 1722 |
container, _, err := runtime.Create( |
| 1723 |
- &Config{
|
|
| 1723 |
+ &docker.Config{
|
|
| 1724 | 1724 |
Image: GetTestImage(runtime).ID, |
| 1725 | 1725 |
Cmd: []string{"sh", "-c", "echo -n bar > /test/foo"},
|
| 1726 | 1726 |
Volumes: map[string]struct{}{"/test": {}},
|
| ... | ... |
@@ -3,6 +3,7 @@ package docker |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"fmt" |
| 6 |
+ "github.com/dotcloud/docker" |
|
| 6 | 7 |
"github.com/dotcloud/docker/engine" |
| 7 | 8 |
"github.com/dotcloud/docker/sysinit" |
| 8 | 9 |
"github.com/dotcloud/docker/utils" |
| ... | ... |
@@ -15,7 +16,6 @@ import ( |
| 15 | 15 |
"runtime" |
| 16 | 16 |
"strconv" |
| 17 | 17 |
"strings" |
| 18 |
- "sync" |
|
| 19 | 18 |
"syscall" |
| 20 | 19 |
"testing" |
| 21 | 20 |
"time" |
| ... | ... |
@@ -32,39 +32,33 @@ const ( |
| 32 | 32 |
) |
| 33 | 33 |
|
| 34 | 34 |
var ( |
| 35 |
- globalRuntime *Runtime |
|
| 35 |
+ // FIXME: globalRuntime is deprecated by globalEngine. All tests should be converted. |
|
| 36 |
+ globalRuntime *docker.Runtime |
|
| 37 |
+ globalEngine *engine.Engine |
|
| 36 | 38 |
startFds int |
| 37 | 39 |
startGoroutines int |
| 38 | 40 |
) |
| 39 | 41 |
|
| 40 |
-func nuke(runtime *Runtime) error {
|
|
| 41 |
- var wg sync.WaitGroup |
|
| 42 |
- for _, container := range runtime.List() {
|
|
| 43 |
- wg.Add(1) |
|
| 44 |
- go func(c *Container) {
|
|
| 45 |
- c.Kill() |
|
| 46 |
- wg.Done() |
|
| 47 |
- }(container) |
|
| 48 |
- } |
|
| 49 |
- wg.Wait() |
|
| 50 |
- runtime.Close() |
|
| 51 |
- |
|
| 52 |
- os.Remove(filepath.Join(runtime.config.Root, "linkgraph.db")) |
|
| 53 |
- return os.RemoveAll(runtime.config.Root) |
|
| 42 |
+// FIXME: nuke() is deprecated by Runtime.Nuke() |
|
| 43 |
+func nuke(runtime *docker.Runtime) error {
|
|
| 44 |
+ return runtime.Nuke() |
|
| 54 | 45 |
} |
| 55 | 46 |
|
| 56 |
-func cleanup(runtime *Runtime) error {
|
|
| 47 |
+// FIXME: cleanup and nuke are redundant. |
|
| 48 |
+func cleanup(eng *engine.Engine, t *testing.T) error {
|
|
| 49 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 57 | 50 |
for _, container := range runtime.List() {
|
| 58 | 51 |
container.Kill() |
| 59 | 52 |
runtime.Destroy(container) |
| 60 | 53 |
} |
| 61 |
- images, err := runtime.graph.Map() |
|
| 54 |
+ srv := mkServerFromEngine(eng, t) |
|
| 55 |
+ images, err := srv.Images(true, "") |
|
| 62 | 56 |
if err != nil {
|
| 63 | 57 |
return err |
| 64 | 58 |
} |
| 65 | 59 |
for _, image := range images {
|
| 66 | 60 |
if image.ID != unitTestImageID {
|
| 67 |
- runtime.graph.Delete(image.ID) |
|
| 61 |
+ srv.ImageDelete(image.ID, false) |
|
| 68 | 62 |
} |
| 69 | 63 |
} |
| 70 | 64 |
return nil |
| ... | ... |
@@ -133,10 +127,9 @@ func setupBaseImage() {
|
| 133 | 133 |
log.Fatalf("Unable to create a runtime for tests:", err)
|
| 134 | 134 |
} |
| 135 | 135 |
srv := mkServerFromEngine(eng, log.New(os.Stderr, "", 0)) |
| 136 |
- runtime := srv.runtime |
|
| 137 | 136 |
|
| 138 | 137 |
// If the unit test is not found, try to download it. |
| 139 |
- if img, err := runtime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID {
|
|
| 138 |
+ if img, err := srv.ImageInspect(unitTestImageName); err != nil || img.ID != unitTestImageID {
|
|
| 140 | 139 |
// Retrieve the Image |
| 141 | 140 |
if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil, nil, true); err != nil {
|
| 142 | 141 |
log.Fatalf("Unable to pull the test image: %s", err)
|
| ... | ... |
@@ -151,8 +144,8 @@ func spawnGlobalDaemon() {
|
| 151 | 151 |
} |
| 152 | 152 |
t := log.New(os.Stderr, "", 0) |
| 153 | 153 |
eng := NewTestEngine(t) |
| 154 |
- srv := mkServerFromEngine(eng, t) |
|
| 155 |
- globalRuntime = srv.runtime |
|
| 154 |
+ globalEngine = eng |
|
| 155 |
+ globalRuntime = mkRuntimeFromEngine(eng, t) |
|
| 156 | 156 |
|
| 157 | 157 |
// Spawn a Daemon |
| 158 | 158 |
go func() {
|
| ... | ... |
@@ -174,8 +167,8 @@ func spawnGlobalDaemon() {
|
| 174 | 174 |
|
| 175 | 175 |
// FIXME: test that ImagePull(json=true) send correct json output |
| 176 | 176 |
|
| 177 |
-func GetTestImage(runtime *Runtime) *Image {
|
|
| 178 |
- imgs, err := runtime.graph.Map() |
|
| 177 |
+func GetTestImage(runtime *docker.Runtime) *docker.Image {
|
|
| 178 |
+ imgs, err := runtime.Graph().Map() |
|
| 179 | 179 |
if err != nil {
|
| 180 | 180 |
log.Fatalf("Unable to get the test image:", err)
|
| 181 | 181 |
} |
| ... | ... |
@@ -184,7 +177,7 @@ func GetTestImage(runtime *Runtime) *Image {
|
| 184 | 184 |
return image |
| 185 | 185 |
} |
| 186 | 186 |
} |
| 187 |
- log.Fatalf("Test image %v not found in %s: %s", unitTestImageID, runtime.graph.Root, imgs)
|
|
| 187 |
+ log.Fatalf("Test image %v not found in %s: %s", unitTestImageID, runtime.Graph().Root, imgs)
|
|
| 188 | 188 |
return nil |
| 189 | 189 |
} |
| 190 | 190 |
|
| ... | ... |
@@ -197,7 +190,7 @@ func TestRuntimeCreate(t *testing.T) {
|
| 197 | 197 |
t.Errorf("Expected 0 containers, %v found", len(runtime.List()))
|
| 198 | 198 |
} |
| 199 | 199 |
|
| 200 |
- container, _, err := runtime.Create(&Config{
|
|
| 200 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 201 | 201 |
Image: GetTestImage(runtime).ID, |
| 202 | 202 |
Cmd: []string{"ls", "-al"},
|
| 203 | 203 |
}, |
| ... | ... |
@@ -239,12 +232,12 @@ func TestRuntimeCreate(t *testing.T) {
|
| 239 | 239 |
} |
| 240 | 240 |
|
| 241 | 241 |
// Make sure create with bad parameters returns an error |
| 242 |
- if _, _, err = runtime.Create(&Config{Image: GetTestImage(runtime).ID}, ""); err == nil {
|
|
| 242 |
+ if _, _, err = runtime.Create(&docker.Config{Image: GetTestImage(runtime).ID}, ""); err == nil {
|
|
| 243 | 243 |
t.Fatal("Builder.Create should throw an error when Cmd is missing")
|
| 244 | 244 |
} |
| 245 | 245 |
|
| 246 | 246 |
if _, _, err := runtime.Create( |
| 247 |
- &Config{
|
|
| 247 |
+ &docker.Config{
|
|
| 248 | 248 |
Image: GetTestImage(runtime).ID, |
| 249 | 249 |
Cmd: []string{},
|
| 250 | 250 |
}, |
| ... | ... |
@@ -253,7 +246,7 @@ func TestRuntimeCreate(t *testing.T) {
|
| 253 | 253 |
t.Fatal("Builder.Create should throw an error when Cmd is empty")
|
| 254 | 254 |
} |
| 255 | 255 |
|
| 256 |
- config := &Config{
|
|
| 256 |
+ config := &docker.Config{
|
|
| 257 | 257 |
Image: GetTestImage(runtime).ID, |
| 258 | 258 |
Cmd: []string{"/bin/ls"},
|
| 259 | 259 |
PortSpecs: []string{"80"},
|
| ... | ... |
@@ -266,7 +259,7 @@ func TestRuntimeCreate(t *testing.T) {
|
| 266 | 266 |
} |
| 267 | 267 |
|
| 268 | 268 |
// test expose 80:8000 |
| 269 |
- container, warnings, err := runtime.Create(&Config{
|
|
| 269 |
+ container, warnings, err := runtime.Create(&docker.Config{
|
|
| 270 | 270 |
Image: GetTestImage(runtime).ID, |
| 271 | 271 |
Cmd: []string{"ls", "-al"},
|
| 272 | 272 |
PortSpecs: []string{"80:8000"},
|
| ... | ... |
@@ -285,7 +278,7 @@ func TestDestroy(t *testing.T) {
|
| 285 | 285 |
runtime := mkRuntime(t) |
| 286 | 286 |
defer nuke(runtime) |
| 287 | 287 |
|
| 288 |
- container, _, err := runtime.Create(&Config{
|
|
| 288 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 289 | 289 |
Image: GetTestImage(runtime).ID, |
| 290 | 290 |
Cmd: []string{"ls", "-al"},
|
| 291 | 291 |
}, "") |
| ... | ... |
@@ -312,12 +305,6 @@ func TestDestroy(t *testing.T) {
|
| 312 | 312 |
t.Errorf("Unable to get newly created container")
|
| 313 | 313 |
} |
| 314 | 314 |
|
| 315 |
- // Make sure the container root directory does not exist anymore |
|
| 316 |
- _, err = os.Stat(container.root) |
|
| 317 |
- if err == nil || !os.IsNotExist(err) {
|
|
| 318 |
- t.Errorf("Container root directory still exists after destroy")
|
|
| 319 |
- } |
|
| 320 |
- |
|
| 321 | 315 |
// Test double destroy |
| 322 | 316 |
if err := runtime.Destroy(container); err == nil {
|
| 323 | 317 |
// It should have failed |
| ... | ... |
@@ -352,15 +339,21 @@ func TestGet(t *testing.T) {
|
| 352 | 352 |
|
| 353 | 353 |
} |
| 354 | 354 |
|
| 355 |
-func startEchoServerContainer(t *testing.T, proto string) (*Runtime, *Container, string) {
|
|
| 355 |
+func startEchoServerContainer(t *testing.T, proto string) (*docker.Runtime, *docker.Container, string) {
|
|
| 356 | 356 |
var ( |
| 357 |
- err error |
|
| 358 |
- container *Container |
|
| 359 |
- strPort string |
|
| 360 |
- runtime = mkRuntime(t) |
|
| 361 |
- port = 5554 |
|
| 362 |
- p Port |
|
| 357 |
+ err error |
|
| 358 |
+ id string |
|
| 359 |
+ strPort string |
|
| 360 |
+ eng = NewTestEngine(t) |
|
| 361 |
+ runtime = mkRuntimeFromEngine(eng, t) |
|
| 362 |
+ port = 5554 |
|
| 363 |
+ p docker.Port |
|
| 363 | 364 |
) |
| 365 |
+ defer func() {
|
|
| 366 |
+ if err != nil {
|
|
| 367 |
+ runtime.Nuke() |
|
| 368 |
+ } |
|
| 369 |
+ }() |
|
| 364 | 370 |
|
| 365 | 371 |
for {
|
| 366 | 372 |
port += 1 |
| ... | ... |
@@ -373,37 +366,45 @@ func startEchoServerContainer(t *testing.T, proto string) (*Runtime, *Container, |
| 373 | 373 |
} else {
|
| 374 | 374 |
t.Fatal(fmt.Errorf("Unknown protocol %v", proto))
|
| 375 | 375 |
} |
| 376 |
- ep := make(map[Port]struct{}, 1)
|
|
| 377 |
- p = Port(fmt.Sprintf("%s/%s", strPort, proto))
|
|
| 376 |
+ ep := make(map[docker.Port]struct{}, 1)
|
|
| 377 |
+ p = docker.Port(fmt.Sprintf("%s/%s", strPort, proto))
|
|
| 378 | 378 |
ep[p] = struct{}{}
|
| 379 | 379 |
|
| 380 |
- container, _, err = runtime.Create(&Config{
|
|
| 381 |
- Image: GetTestImage(runtime).ID, |
|
| 382 |
- Cmd: []string{"sh", "-c", cmd},
|
|
| 383 |
- PortSpecs: []string{fmt.Sprintf("%s/%s", strPort, proto)},
|
|
| 384 |
- ExposedPorts: ep, |
|
| 385 |
- }, "") |
|
| 386 |
- if err != nil {
|
|
| 387 |
- nuke(runtime) |
|
| 380 |
+ jobCreate := eng.Job("create")
|
|
| 381 |
+ jobCreate.Setenv("Image", unitTestImageID)
|
|
| 382 |
+ jobCreate.SetenvList("Cmd", []string{"sh", "-c", cmd})
|
|
| 383 |
+ jobCreate.SetenvList("PortSpecs", []string{fmt.Sprintf("%s/%s", strPort, proto)})
|
|
| 384 |
+ jobCreate.SetenvJson("ExposedPorts", ep)
|
|
| 385 |
+ jobCreate.StdoutParseString(&id) |
|
| 386 |
+ if err := jobCreate.Run(); err != nil {
|
|
| 388 | 387 |
t.Fatal(err) |
| 389 | 388 |
} |
| 390 |
- |
|
| 391 |
- if container != nil {
|
|
| 389 |
+ // FIXME: this relies on the undocumented behavior of runtime.Create |
|
| 390 |
+ // which will return a nil error AND container if the exposed ports |
|
| 391 |
+ // are invalid. That behavior should be fixed! |
|
| 392 |
+ if id != "" {
|
|
| 392 | 393 |
break |
| 393 | 394 |
} |
| 394 | 395 |
t.Logf("Port %v already in use, trying another one", strPort)
|
| 395 |
- } |
|
| 396 | 396 |
|
| 397 |
- container.hostConfig = &HostConfig{
|
|
| 398 |
- PortBindings: make(map[Port][]PortBinding), |
|
| 399 | 397 |
} |
| 400 |
- container.hostConfig.PortBindings[p] = []PortBinding{
|
|
| 398 |
+ |
|
| 399 |
+ jobStart := eng.Job("start", id)
|
|
| 400 |
+ portBindings := make(map[docker.Port][]docker.PortBinding) |
|
| 401 |
+ portBindings[p] = []docker.PortBinding{
|
|
| 401 | 402 |
{},
|
| 402 | 403 |
} |
| 403 |
- if err := container.Start(); err != nil {
|
|
| 404 |
- nuke(runtime) |
|
| 404 |
+ if err := jobStart.SetenvJson("PortsBindings", portBindings); err != nil {
|
|
| 405 | 405 |
t.Fatal(err) |
| 406 | 406 |
} |
| 407 |
+ if err := jobStart.Run(); err != nil {
|
|
| 408 |
+ t.Fatal(err) |
|
| 409 |
+ } |
|
| 410 |
+ |
|
| 411 |
+ container := runtime.Get(id) |
|
| 412 |
+ if container == nil {
|
|
| 413 |
+ t.Fatalf("Couldn't fetch test container %s", id)
|
|
| 414 |
+ } |
|
| 407 | 415 |
|
| 408 | 416 |
setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
|
| 409 | 417 |
for !container.State.Running {
|
| ... | ... |
@@ -504,8 +505,9 @@ func TestAllocateUDPPortLocalhost(t *testing.T) {
|
| 504 | 504 |
} |
| 505 | 505 |
|
| 506 | 506 |
func TestRestore(t *testing.T) {
|
| 507 |
- runtime1 := mkRuntime(t) |
|
| 508 |
- defer nuke(runtime1) |
|
| 507 |
+ eng := NewTestEngine(t) |
|
| 508 |
+ runtime1 := mkRuntimeFromEngine(eng, t) |
|
| 509 |
+ defer runtime1.Nuke() |
|
| 509 | 510 |
// Create a container with one instance of docker |
| 510 | 511 |
container1, _ := mkContainer(runtime1, []string{"_", "ls", "-al"}, t)
|
| 511 | 512 |
defer runtime1.Destroy(container1) |
| ... | ... |
@@ -545,12 +547,14 @@ func TestRestore(t *testing.T) {
|
| 545 | 545 |
|
| 546 | 546 |
// Here are are simulating a docker restart - that is, reloading all containers |
| 547 | 547 |
// from scratch |
| 548 |
- runtime1.config.AutoRestart = false |
|
| 549 |
- runtime2, err := NewRuntimeFromDirectory(runtime1.config) |
|
| 550 |
- if err != nil {
|
|
| 548 |
+ job := eng.Job("initapi")
|
|
| 549 |
+ job.Setenv("Root", eng.Root())
|
|
| 550 |
+ job.SetenvBool("AutoRestart", false)
|
|
| 551 |
+ if err := job.Run(); err != nil {
|
|
| 551 | 552 |
t.Fatal(err) |
| 552 | 553 |
} |
| 553 |
- defer nuke(runtime2) |
|
| 554 |
+ |
|
| 555 |
+ runtime2 := mkRuntimeFromEngine(eng, t) |
|
| 554 | 556 |
if len(runtime2.List()) != 2 {
|
| 555 | 557 |
t.Errorf("Expected 2 container, %v found", len(runtime2.List()))
|
| 556 | 558 |
} |
| ... | ... |
@@ -575,7 +579,24 @@ func TestRestore(t *testing.T) {
|
| 575 | 575 |
} |
| 576 | 576 |
|
| 577 | 577 |
func TestReloadContainerLinks(t *testing.T) {
|
| 578 |
- runtime1 := mkRuntime(t) |
|
| 578 |
+ // FIXME: here we don't use NewTestEngine because it calls initapi with Autorestart=false, |
|
| 579 |
+ // and we want to set it to true. |
|
| 580 |
+ root, err := newTestDirectory(unitTestStoreBase) |
|
| 581 |
+ if err != nil {
|
|
| 582 |
+ t.Fatal(err) |
|
| 583 |
+ } |
|
| 584 |
+ eng, err := engine.New(root) |
|
| 585 |
+ if err != nil {
|
|
| 586 |
+ t.Fatal(err) |
|
| 587 |
+ } |
|
| 588 |
+ job := eng.Job("initapi")
|
|
| 589 |
+ job.Setenv("Root", eng.Root())
|
|
| 590 |
+ job.SetenvBool("Autorestart", true)
|
|
| 591 |
+ if err := job.Run(); err != nil {
|
|
| 592 |
+ t.Fatal(err) |
|
| 593 |
+ } |
|
| 594 |
+ |
|
| 595 |
+ runtime1 := mkRuntimeFromEngine(eng, t) |
|
| 579 | 596 |
defer nuke(runtime1) |
| 580 | 597 |
// Create a container with one instance of docker |
| 581 | 598 |
container1, _ := mkContainer(runtime1, []string{"-i", "_", "/bin/sh"}, t)
|
| ... | ... |
@@ -590,7 +611,9 @@ func TestReloadContainerLinks(t *testing.T) {
|
| 590 | 590 |
t.Fatal(err) |
| 591 | 591 |
} |
| 592 | 592 |
// Add a link to container 2 |
| 593 |
- container1.hostConfig.Links = []string{"/" + container2.ID + ":first"}
|
|
| 593 |
+ // FIXME @shykes: setting hostConfig.Links seems redundant with calling RegisterLink(). |
|
| 594 |
+ // Why do we need it @crosbymichael? |
|
| 595 |
+ // container1.hostConfig.Links = []string{"/" + container2.ID + ":first"}
|
|
| 594 | 596 |
if err := runtime1.RegisterLink(container1, container2, "first"); err != nil {
|
| 595 | 597 |
t.Fatal(err) |
| 596 | 598 |
} |
| ... | ... |
@@ -612,12 +635,13 @@ func TestReloadContainerLinks(t *testing.T) {
|
| 612 | 612 |
|
| 613 | 613 |
// Here are are simulating a docker restart - that is, reloading all containers |
| 614 | 614 |
// from scratch |
| 615 |
- runtime1.config.AutoRestart = true |
|
| 616 |
- runtime2, err := NewRuntimeFromDirectory(runtime1.config) |
|
| 617 |
- if err != nil {
|
|
| 615 |
+ job = eng.Job("initapi")
|
|
| 616 |
+ job.Setenv("Root", eng.Root())
|
|
| 617 |
+ job.SetenvBool("AutoRestart", false)
|
|
| 618 |
+ if err := job.Run(); err != nil {
|
|
| 618 | 619 |
t.Fatal(err) |
| 619 | 620 |
} |
| 620 |
- defer nuke(runtime2) |
|
| 621 |
+ runtime2 := mkRuntimeFromEngine(eng, t) |
|
| 621 | 622 |
if len(runtime2.List()) != 2 {
|
| 622 | 623 |
t.Errorf("Expected 2 container, %v found", len(runtime2.List()))
|
| 623 | 624 |
} |
| ... | ... |
@@ -631,27 +655,32 @@ func TestReloadContainerLinks(t *testing.T) {
|
| 631 | 631 |
t.Fatalf("Expected 2 container alive, %d found", runningCount)
|
| 632 | 632 |
} |
| 633 | 633 |
|
| 634 |
+ // FIXME: we no longer test if containers were registered in the right order, |
|
| 635 |
+ // because there is no public |
|
| 634 | 636 |
// Make sure container 2 ( the child of container 1 ) was registered and started first |
| 635 | 637 |
// with the runtime |
| 636 |
- first := runtime2.containers.Front() |
|
| 637 |
- if first.Value.(*Container).ID != container2.ID {
|
|
| 638 |
+ // |
|
| 639 |
+ containers := runtime2.List() |
|
| 640 |
+ if len(containers) == 0 {
|
|
| 641 |
+ t.Fatalf("Runtime has no containers")
|
|
| 642 |
+ } |
|
| 643 |
+ first := containers[0] |
|
| 644 |
+ if first.ID != container2.ID {
|
|
| 638 | 645 |
t.Fatalf("Container 2 %s should be registered first in the runtime", container2.ID)
|
| 639 | 646 |
} |
| 640 | 647 |
|
| 641 | 648 |
// Verify that the link is still registered in the runtime |
| 642 |
- entity := runtime2.containerGraph.Get(container1.Name) |
|
| 643 |
- if entity == nil {
|
|
| 644 |
- t.Fatal("Entity should not be nil")
|
|
| 649 |
+ if c := runtime2.Get(container1.Name); c == nil {
|
|
| 650 |
+ t.Fatal("Named container is no longer registered after restart")
|
|
| 645 | 651 |
} |
| 646 | 652 |
} |
| 647 | 653 |
|
| 648 | 654 |
func TestDefaultContainerName(t *testing.T) {
|
| 649 | 655 |
eng := NewTestEngine(t) |
| 650 |
- srv := mkServerFromEngine(eng, t) |
|
| 651 |
- runtime := srv.runtime |
|
| 656 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 652 | 657 |
defer nuke(runtime) |
| 653 | 658 |
|
| 654 |
- config, _, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 659 |
+ config, _, _, err := docker.ParseRun([]string{unitTestImageID, "echo test"}, nil)
|
|
| 655 | 660 |
if err != nil {
|
| 656 | 661 |
t.Fatal(err) |
| 657 | 662 |
} |
| ... | ... |
@@ -663,29 +692,19 @@ func TestDefaultContainerName(t *testing.T) {
|
| 663 | 663 |
t.Fatalf("Expect /some_name got %s", container.Name)
|
| 664 | 664 |
} |
| 665 | 665 |
|
| 666 |
- paths := runtime.containerGraph.RefPaths(containerID) |
|
| 667 |
- if paths == nil || len(paths) == 0 {
|
|
| 668 |
- t.Fatalf("Could not find edges for %s", containerID)
|
|
| 669 |
- } |
|
| 670 |
- edge := paths[0] |
|
| 671 |
- if edge.ParentID != "0" {
|
|
| 672 |
- t.Fatalf("Expected engine got %s", edge.ParentID)
|
|
| 673 |
- } |
|
| 674 |
- if edge.EntityID != containerID {
|
|
| 675 |
- t.Fatalf("Expected %s got %s", containerID, edge.EntityID)
|
|
| 676 |
- } |
|
| 677 |
- if edge.Name != "some_name" {
|
|
| 678 |
- t.Fatalf("Expected some_name got %s", edge.Name)
|
|
| 666 |
+ if c := runtime.Get("/some_name"); c == nil {
|
|
| 667 |
+ t.Fatalf("Couldn't retrieve test container as /some_name")
|
|
| 668 |
+ } else if c.ID != containerID {
|
|
| 669 |
+ t.Fatalf("Container /some_name has ID %s instead of %s", c.ID, containerID)
|
|
| 679 | 670 |
} |
| 680 | 671 |
} |
| 681 | 672 |
|
| 682 | 673 |
func TestRandomContainerName(t *testing.T) {
|
| 683 | 674 |
eng := NewTestEngine(t) |
| 684 |
- srv := mkServerFromEngine(eng, t) |
|
| 685 |
- runtime := srv.runtime |
|
| 675 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 686 | 676 |
defer nuke(runtime) |
| 687 | 677 |
|
| 688 |
- config, _, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 678 |
+ config, _, _, err := docker.ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 689 | 679 |
if err != nil {
|
| 690 | 680 |
t.Fatal(err) |
| 691 | 681 |
} |
| ... | ... |
@@ -697,29 +716,19 @@ func TestRandomContainerName(t *testing.T) {
|
| 697 | 697 |
t.Fatalf("Expected not empty container name")
|
| 698 | 698 |
} |
| 699 | 699 |
|
| 700 |
- paths := runtime.containerGraph.RefPaths(containerID) |
|
| 701 |
- if paths == nil || len(paths) == 0 {
|
|
| 702 |
- t.Fatalf("Could not find edges for %s", containerID)
|
|
| 703 |
- } |
|
| 704 |
- edge := paths[0] |
|
| 705 |
- if edge.ParentID != "0" {
|
|
| 706 |
- t.Fatalf("Expected engine got %s", edge.ParentID)
|
|
| 707 |
- } |
|
| 708 |
- if edge.EntityID != containerID {
|
|
| 709 |
- t.Fatalf("Expected %s got %s", containerID, edge.EntityID)
|
|
| 710 |
- } |
|
| 711 |
- if edge.Name == "" {
|
|
| 712 |
- t.Fatalf("Expected not empty container name")
|
|
| 700 |
+ if c := runtime.Get(container.Name); c == nil {
|
|
| 701 |
+ log.Fatalf("Could not lookup container %s by its name", container.Name)
|
|
| 702 |
+ } else if c.ID != containerID {
|
|
| 703 |
+ log.Fatalf("Looking up container name %s returned id %s instead of %s", container.Name, c.ID, containerID)
|
|
| 713 | 704 |
} |
| 714 | 705 |
} |
| 715 | 706 |
|
| 716 | 707 |
func TestLinkChildContainer(t *testing.T) {
|
| 717 | 708 |
eng := NewTestEngine(t) |
| 718 |
- srv := mkServerFromEngine(eng, t) |
|
| 719 |
- runtime := srv.runtime |
|
| 709 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 720 | 710 |
defer nuke(runtime) |
| 721 | 711 |
|
| 722 |
- config, _, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 712 |
+ config, _, _, err := docker.ParseRun([]string{unitTestImageID, "echo test"}, nil)
|
|
| 723 | 713 |
if err != nil {
|
| 724 | 714 |
t.Fatal(err) |
| 725 | 715 |
} |
| ... | ... |
@@ -735,7 +744,7 @@ func TestLinkChildContainer(t *testing.T) {
|
| 735 | 735 |
t.Fatalf("Expect webapp id to match container id: %s != %s", webapp.ID, container.ID)
|
| 736 | 736 |
} |
| 737 | 737 |
|
| 738 |
- config, _, _, err = ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 738 |
+ config, _, _, err = docker.ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 739 | 739 |
if err != nil {
|
| 740 | 740 |
t.Fatal(err) |
| 741 | 741 |
} |
| ... | ... |
@@ -758,11 +767,10 @@ func TestLinkChildContainer(t *testing.T) {
|
| 758 | 758 |
|
| 759 | 759 |
func TestGetAllChildren(t *testing.T) {
|
| 760 | 760 |
eng := NewTestEngine(t) |
| 761 |
- srv := mkServerFromEngine(eng, t) |
|
| 762 |
- runtime := srv.runtime |
|
| 761 |
+ runtime := mkRuntimeFromEngine(eng, t) |
|
| 763 | 762 |
defer nuke(runtime) |
| 764 | 763 |
|
| 765 |
- config, _, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 764 |
+ config, _, _, err := docker.ParseRun([]string{unitTestImageID, "echo test"}, nil)
|
|
| 766 | 765 |
if err != nil {
|
| 767 | 766 |
t.Fatal(err) |
| 768 | 767 |
} |
| ... | ... |
@@ -778,7 +786,7 @@ func TestGetAllChildren(t *testing.T) {
|
| 778 | 778 |
t.Fatalf("Expect webapp id to match container id: %s != %s", webapp.ID, container.ID)
|
| 779 | 779 |
} |
| 780 | 780 |
|
| 781 |
- config, _, _, err = ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 781 |
+ config, _, _, err = docker.ParseRun([]string{unitTestImageID, "echo test"}, nil)
|
|
| 782 | 782 |
if err != nil {
|
| 783 | 783 |
t.Fatal(err) |
| 784 | 784 |
} |
| ... | ... |
@@ -810,19 +818,3 @@ func TestGetAllChildren(t *testing.T) {
|
| 810 | 810 |
} |
| 811 | 811 |
} |
| 812 | 812 |
} |
| 813 |
- |
|
| 814 |
-func TestGetFullName(t *testing.T) {
|
|
| 815 |
- runtime := mkRuntime(t) |
|
| 816 |
- defer nuke(runtime) |
|
| 817 |
- |
|
| 818 |
- name, err := runtime.getFullName("testing")
|
|
| 819 |
- if err != nil {
|
|
| 820 |
- t.Fatal(err) |
|
| 821 |
- } |
|
| 822 |
- if name != "/testing" {
|
|
| 823 |
- t.Fatalf("Expected /testing got %s", name)
|
|
| 824 |
- } |
|
| 825 |
- if _, err := runtime.getFullName(""); err == nil {
|
|
| 826 |
- t.Fatal("Error should not be nil")
|
|
| 827 |
- } |
|
| 828 |
-} |
| ... | ... |
@@ -1,32 +1,31 @@ |
| 1 | 1 |
package docker |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "github.com/dotcloud/docker" |
|
| 4 | 5 |
"github.com/dotcloud/docker/utils" |
| 5 | 6 |
"io/ioutil" |
| 6 | 7 |
"strings" |
| 7 | 8 |
"testing" |
| 8 |
- "time" |
|
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
func TestContainerTagImageDelete(t *testing.T) {
|
| 12 |
- runtime := mkRuntime(t) |
|
| 13 |
- defer nuke(runtime) |
|
| 12 |
+ eng := NewTestEngine(t) |
|
| 13 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 14 | 14 |
|
| 15 |
- srv := &Server{runtime: runtime}
|
|
| 15 |
+ srv := mkServerFromEngine(eng, t) |
|
| 16 | 16 |
|
| 17 | 17 |
initialImages, err := srv.Images(false, "") |
| 18 | 18 |
if err != nil {
|
| 19 | 19 |
t.Fatal(err) |
| 20 | 20 |
} |
| 21 |
- |
|
| 22 |
- if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
|
| 21 |
+ if err := srv.ContainerTag(unitTestImageName, "utest", "tag1", false); err != nil {
|
|
| 23 | 22 |
t.Fatal(err) |
| 24 | 23 |
} |
| 25 | 24 |
|
| 26 |
- if err := srv.runtime.repositories.Set("utest/docker", "tag2", unitTestImageName, false); err != nil {
|
|
| 25 |
+ if err := srv.ContainerTag(unitTestImageName, "utest/docker", "tag2", false); err != nil {
|
|
| 27 | 26 |
t.Fatal(err) |
| 28 | 27 |
} |
| 29 |
- if err := srv.runtime.repositories.Set("utest:5000/docker", "tag3", unitTestImageName, false); err != nil {
|
|
| 28 |
+ if err := srv.ContainerTag(unitTestImageName, "utest:5000/docker", "tag3", false); err != nil {
|
|
| 30 | 29 |
t.Fatal(err) |
| 31 | 30 |
} |
| 32 | 31 |
|
| ... | ... |
@@ -82,46 +81,43 @@ func TestContainerTagImageDelete(t *testing.T) {
|
| 82 | 82 |
func TestCreateRm(t *testing.T) {
|
| 83 | 83 |
eng := NewTestEngine(t) |
| 84 | 84 |
srv := mkServerFromEngine(eng, t) |
| 85 |
- runtime := srv.runtime |
|
| 86 |
- defer nuke(runtime) |
|
| 85 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 87 | 86 |
|
| 88 |
- config, _, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 87 |
+ config, _, _, err := docker.ParseRun([]string{unitTestImageID, "echo test"}, nil)
|
|
| 89 | 88 |
if err != nil {
|
| 90 | 89 |
t.Fatal(err) |
| 91 | 90 |
} |
| 92 | 91 |
|
| 93 | 92 |
id := createTestContainer(eng, config, t) |
| 94 | 93 |
|
| 95 |
- if len(runtime.List()) != 1 {
|
|
| 96 |
- t.Errorf("Expected 1 container, %v found", len(runtime.List()))
|
|
| 94 |
+ if c := srv.Containers(true, false, -1, "", ""); len(c) != 1 {
|
|
| 95 |
+ t.Errorf("Expected 1 container, %v found", len(c))
|
|
| 97 | 96 |
} |
| 98 | 97 |
|
| 99 | 98 |
if err = srv.ContainerDestroy(id, true, false); err != nil {
|
| 100 | 99 |
t.Fatal(err) |
| 101 | 100 |
} |
| 102 | 101 |
|
| 103 |
- if len(runtime.List()) != 0 {
|
|
| 104 |
- t.Errorf("Expected 0 container, %v found", len(runtime.List()))
|
|
| 102 |
+ if c := srv.Containers(true, false, -1, "", ""); len(c) != 0 {
|
|
| 103 |
+ t.Errorf("Expected 0 container, %v found", len(c))
|
|
| 105 | 104 |
} |
| 106 | 105 |
|
| 107 | 106 |
} |
| 108 | 107 |
|
| 109 | 108 |
func TestCreateRmVolumes(t *testing.T) {
|
| 110 | 109 |
eng := NewTestEngine(t) |
| 111 |
- |
|
| 112 | 110 |
srv := mkServerFromEngine(eng, t) |
| 113 |
- runtime := srv.runtime |
|
| 114 |
- defer nuke(runtime) |
|
| 111 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 115 | 112 |
|
| 116 |
- config, hostConfig, _, err := ParseRun([]string{"-v", "/srv", GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 113 |
+ config, hostConfig, _, err := docker.ParseRun([]string{"-v", "/srv", unitTestImageID, "echo test"}, nil)
|
|
| 117 | 114 |
if err != nil {
|
| 118 | 115 |
t.Fatal(err) |
| 119 | 116 |
} |
| 120 | 117 |
|
| 121 | 118 |
id := createTestContainer(eng, config, t) |
| 122 | 119 |
|
| 123 |
- if len(runtime.List()) != 1 {
|
|
| 124 |
- t.Errorf("Expected 1 container, %v found", len(runtime.List()))
|
|
| 120 |
+ if c := srv.Containers(true, false, -1, "", ""); len(c) != 1 {
|
|
| 121 |
+ t.Errorf("Expected 1 container, %v found", len(c))
|
|
| 125 | 122 |
} |
| 126 | 123 |
|
| 127 | 124 |
job := eng.Job("start", id)
|
| ... | ... |
@@ -141,18 +137,17 @@ func TestCreateRmVolumes(t *testing.T) {
|
| 141 | 141 |
t.Fatal(err) |
| 142 | 142 |
} |
| 143 | 143 |
|
| 144 |
- if len(runtime.List()) != 0 {
|
|
| 145 |
- t.Errorf("Expected 0 container, %v found", len(runtime.List()))
|
|
| 144 |
+ if c := srv.Containers(true, false, -1, "", ""); len(c) != 0 {
|
|
| 145 |
+ t.Errorf("Expected 0 container, %v found", len(c))
|
|
| 146 | 146 |
} |
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 | 149 |
func TestCommit(t *testing.T) {
|
| 150 | 150 |
eng := NewTestEngine(t) |
| 151 | 151 |
srv := mkServerFromEngine(eng, t) |
| 152 |
- runtime := srv.runtime |
|
| 153 |
- defer nuke(runtime) |
|
| 152 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 154 | 153 |
|
| 155 |
- config, _, _, err := ParseRun([]string{GetTestImage(runtime).ID, "/bin/cat"}, nil)
|
|
| 154 |
+ config, _, _, err := docker.ParseRun([]string{unitTestImageID, "/bin/cat"}, nil)
|
|
| 156 | 155 |
if err != nil {
|
| 157 | 156 |
t.Fatal(err) |
| 158 | 157 |
} |
| ... | ... |
@@ -167,18 +162,17 @@ func TestCommit(t *testing.T) {
|
| 167 | 167 |
func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
| 168 | 168 |
eng := NewTestEngine(t) |
| 169 | 169 |
srv := mkServerFromEngine(eng, t) |
| 170 |
- runtime := srv.runtime |
|
| 171 |
- defer nuke(runtime) |
|
| 170 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 172 | 171 |
|
| 173 |
- config, hostConfig, _, err := ParseRun([]string{GetTestImage(runtime).ID, "/bin/cat"}, nil)
|
|
| 172 |
+ config, hostConfig, _, err := docker.ParseRun([]string{unitTestImageID, "/bin/cat"}, nil)
|
|
| 174 | 173 |
if err != nil {
|
| 175 | 174 |
t.Fatal(err) |
| 176 | 175 |
} |
| 177 | 176 |
|
| 178 | 177 |
id := createTestContainer(eng, config, t) |
| 179 | 178 |
|
| 180 |
- if len(runtime.List()) != 1 {
|
|
| 181 |
- t.Errorf("Expected 1 container, %v found", len(runtime.List()))
|
|
| 179 |
+ if c := srv.Containers(true, false, -1, "", ""); len(c) != 1 {
|
|
| 180 |
+ t.Errorf("Expected 1 container, %v found", len(c))
|
|
| 182 | 181 |
} |
| 183 | 182 |
|
| 184 | 183 |
job := eng.Job("start", id)
|
| ... | ... |
@@ -214,21 +208,18 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
| 214 | 214 |
t.Fatal(err) |
| 215 | 215 |
} |
| 216 | 216 |
|
| 217 |
- if len(runtime.List()) != 0 {
|
|
| 218 |
- t.Errorf("Expected 0 container, %v found", len(runtime.List()))
|
|
| 217 |
+ if c := srv.Containers(true, false, -1, "", ""); len(c) != 0 {
|
|
| 218 |
+ t.Errorf("Expected 0 container, %v found", len(c))
|
|
| 219 | 219 |
} |
| 220 |
- |
|
| 221 | 220 |
} |
| 222 | 221 |
|
| 223 | 222 |
func TestRunWithTooLowMemoryLimit(t *testing.T) {
|
| 224 | 223 |
eng := NewTestEngine(t) |
| 225 |
- srv := mkServerFromEngine(eng, t) |
|
| 226 |
- runtime := srv.runtime |
|
| 227 |
- defer nuke(runtime) |
|
| 224 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 228 | 225 |
|
| 229 | 226 |
// Try to create a container with a memory limit of 1 byte less than the minimum allowed limit. |
| 230 | 227 |
job := eng.Job("create")
|
| 231 |
- job.Setenv("Image", GetTestImage(runtime).ID)
|
|
| 228 |
+ job.Setenv("Image", unitTestImageID)
|
|
| 232 | 229 |
job.Setenv("Memory", "524287")
|
| 233 | 230 |
job.Setenv("CpuShares", "1000")
|
| 234 | 231 |
job.SetenvList("Cmd", []string{"/bin/cat"})
|
| ... | ... |
@@ -239,163 +230,17 @@ func TestRunWithTooLowMemoryLimit(t *testing.T) {
|
| 239 | 239 |
} |
| 240 | 240 |
} |
| 241 | 241 |
|
| 242 |
-func TestContainerTop(t *testing.T) {
|
|
| 243 |
- t.Skip("Fixme. Skipping test for now. Reported error: 'server_test.go:236: Expected 2 processes, found 1.'")
|
|
| 244 |
- |
|
| 245 |
- runtime := mkRuntime(t) |
|
| 246 |
- defer nuke(runtime) |
|
| 247 |
- |
|
| 248 |
- srv := &Server{runtime: runtime}
|
|
| 249 |
- |
|
| 250 |
- c, _ := mkContainer(runtime, []string{"_", "/bin/sh", "-c", "sleep 2"}, t)
|
|
| 251 |
- c, err := mkContainer(runtime, []string{"_", "/bin/sh", "-c", "sleep 2"}, t)
|
|
| 252 |
- if err != nil {
|
|
| 253 |
- t.Fatal(err) |
|
| 254 |
- } |
|
| 255 |
- |
|
| 256 |
- defer runtime.Destroy(c) |
|
| 257 |
- if err := c.Start(); err != nil {
|
|
| 258 |
- t.Fatal(err) |
|
| 259 |
- } |
|
| 260 |
- |
|
| 261 |
- // Give some time to the process to start |
|
| 262 |
- c.WaitTimeout(500 * time.Millisecond) |
|
| 263 |
- |
|
| 264 |
- if !c.State.Running {
|
|
| 265 |
- t.Errorf("Container should be running")
|
|
| 266 |
- } |
|
| 267 |
- procs, err := srv.ContainerTop(c.ID, "") |
|
| 268 |
- if err != nil {
|
|
| 269 |
- t.Fatal(err) |
|
| 270 |
- } |
|
| 271 |
- |
|
| 272 |
- if len(procs.Processes) != 2 {
|
|
| 273 |
- t.Fatalf("Expected 2 processes, found %d.", len(procs.Processes))
|
|
| 274 |
- } |
|
| 275 |
- |
|
| 276 |
- pos := -1 |
|
| 277 |
- for i := 0; i < len(procs.Titles); i++ {
|
|
| 278 |
- if procs.Titles[i] == "CMD" {
|
|
| 279 |
- pos = i |
|
| 280 |
- break |
|
| 281 |
- } |
|
| 282 |
- } |
|
| 283 |
- |
|
| 284 |
- if pos == -1 {
|
|
| 285 |
- t.Fatalf("Expected CMD, not found.")
|
|
| 286 |
- } |
|
| 287 |
- |
|
| 288 |
- if procs.Processes[0][pos] != "sh" && procs.Processes[0][pos] != "busybox" {
|
|
| 289 |
- t.Fatalf("Expected `busybox` or `sh`, found %s.", procs.Processes[0][pos])
|
|
| 290 |
- } |
|
| 291 |
- |
|
| 292 |
- if procs.Processes[1][pos] != "sh" && procs.Processes[1][pos] != "busybox" {
|
|
| 293 |
- t.Fatalf("Expected `busybox` or `sh`, found %s.", procs.Processes[1][pos])
|
|
| 294 |
- } |
|
| 295 |
-} |
|
| 296 |
- |
|
| 297 |
-func TestPools(t *testing.T) {
|
|
| 298 |
- runtime := mkRuntime(t) |
|
| 299 |
- srv := &Server{
|
|
| 300 |
- runtime: runtime, |
|
| 301 |
- pullingPool: make(map[string]struct{}),
|
|
| 302 |
- pushingPool: make(map[string]struct{}),
|
|
| 303 |
- } |
|
| 304 |
- defer nuke(runtime) |
|
| 305 |
- |
|
| 306 |
- err := srv.poolAdd("pull", "test1")
|
|
| 307 |
- if err != nil {
|
|
| 308 |
- t.Fatal(err) |
|
| 309 |
- } |
|
| 310 |
- err = srv.poolAdd("pull", "test2")
|
|
| 311 |
- if err != nil {
|
|
| 312 |
- t.Fatal(err) |
|
| 313 |
- } |
|
| 314 |
- err = srv.poolAdd("push", "test1")
|
|
| 315 |
- if err == nil || err.Error() != "pull test1 is already in progress" {
|
|
| 316 |
- t.Fatalf("Expected `pull test1 is already in progress`")
|
|
| 317 |
- } |
|
| 318 |
- err = srv.poolAdd("pull", "test1")
|
|
| 319 |
- if err == nil || err.Error() != "pull test1 is already in progress" {
|
|
| 320 |
- t.Fatalf("Expected `pull test1 is already in progress`")
|
|
| 321 |
- } |
|
| 322 |
- err = srv.poolAdd("wait", "test3")
|
|
| 323 |
- if err == nil || err.Error() != "Unknown pool type" {
|
|
| 324 |
- t.Fatalf("Expected `Unknown pool type`")
|
|
| 325 |
- } |
|
| 326 |
- |
|
| 327 |
- err = srv.poolRemove("pull", "test2")
|
|
| 328 |
- if err != nil {
|
|
| 329 |
- t.Fatal(err) |
|
| 330 |
- } |
|
| 331 |
- err = srv.poolRemove("pull", "test2")
|
|
| 332 |
- if err != nil {
|
|
| 333 |
- t.Fatal(err) |
|
| 334 |
- } |
|
| 335 |
- err = srv.poolRemove("pull", "test1")
|
|
| 336 |
- if err != nil {
|
|
| 337 |
- t.Fatal(err) |
|
| 338 |
- } |
|
| 339 |
- err = srv.poolRemove("push", "test1")
|
|
| 340 |
- if err != nil {
|
|
| 341 |
- t.Fatal(err) |
|
| 342 |
- } |
|
| 343 |
- err = srv.poolRemove("wait", "test3")
|
|
| 344 |
- if err == nil || err.Error() != "Unknown pool type" {
|
|
| 345 |
- t.Fatalf("Expected `Unknown pool type`")
|
|
| 346 |
- } |
|
| 347 |
-} |
|
| 348 |
- |
|
| 349 |
-func TestLogEvent(t *testing.T) {
|
|
| 350 |
- runtime := mkRuntime(t) |
|
| 351 |
- defer nuke(runtime) |
|
| 352 |
- srv := &Server{
|
|
| 353 |
- runtime: runtime, |
|
| 354 |
- events: make([]utils.JSONMessage, 0, 64), |
|
| 355 |
- listeners: make(map[string]chan utils.JSONMessage), |
|
| 356 |
- } |
|
| 357 |
- |
|
| 358 |
- srv.LogEvent("fakeaction", "fakeid", "fakeimage")
|
|
| 359 |
- |
|
| 360 |
- listener := make(chan utils.JSONMessage) |
|
| 361 |
- srv.Lock() |
|
| 362 |
- srv.listeners["test"] = listener |
|
| 363 |
- srv.Unlock() |
|
| 364 |
- |
|
| 365 |
- srv.LogEvent("fakeaction2", "fakeid", "fakeimage")
|
|
| 366 |
- |
|
| 367 |
- if len(srv.events) != 2 {
|
|
| 368 |
- t.Fatalf("Expected 2 events, found %d", len(srv.events))
|
|
| 369 |
- } |
|
| 370 |
- go func() {
|
|
| 371 |
- time.Sleep(200 * time.Millisecond) |
|
| 372 |
- srv.LogEvent("fakeaction3", "fakeid", "fakeimage")
|
|
| 373 |
- time.Sleep(200 * time.Millisecond) |
|
| 374 |
- srv.LogEvent("fakeaction4", "fakeid", "fakeimage")
|
|
| 375 |
- }() |
|
| 376 |
- |
|
| 377 |
- setTimeout(t, "Listening for events timed out", 2*time.Second, func() {
|
|
| 378 |
- for i := 2; i < 4; i++ {
|
|
| 379 |
- event := <-listener |
|
| 380 |
- if event != srv.events[i] {
|
|
| 381 |
- t.Fatalf("Event received it different than expected")
|
|
| 382 |
- } |
|
| 383 |
- } |
|
| 384 |
- }) |
|
| 385 |
-} |
|
| 386 |
- |
|
| 387 | 242 |
func TestRmi(t *testing.T) {
|
| 388 | 243 |
eng := NewTestEngine(t) |
| 389 | 244 |
srv := mkServerFromEngine(eng, t) |
| 390 |
- runtime := srv.runtime |
|
| 391 |
- defer nuke(runtime) |
|
| 245 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 392 | 246 |
|
| 393 | 247 |
initialImages, err := srv.Images(false, "") |
| 394 | 248 |
if err != nil {
|
| 395 | 249 |
t.Fatal(err) |
| 396 | 250 |
} |
| 397 | 251 |
|
| 398 |
- config, hostConfig, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
|
| 252 |
+ config, hostConfig, _, err := docker.ParseRun([]string{unitTestImageID, "echo test"}, nil)
|
|
| 399 | 253 |
if err != nil {
|
| 400 | 254 |
t.Fatal(err) |
| 401 | 255 |
} |
| ... | ... |
@@ -471,19 +316,19 @@ func TestRmi(t *testing.T) {
|
| 471 | 471 |
} |
| 472 | 472 |
|
| 473 | 473 |
func TestImagesFilter(t *testing.T) {
|
| 474 |
- runtime := mkRuntime(t) |
|
| 475 |
- defer nuke(runtime) |
|
| 474 |
+ eng := NewTestEngine(t) |
|
| 475 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 476 | 476 |
|
| 477 |
- srv := &Server{runtime: runtime}
|
|
| 477 |
+ srv := mkServerFromEngine(eng, t) |
|
| 478 | 478 |
|
| 479 |
- if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
|
| 479 |
+ if err := srv.ContainerTag(unitTestImageName, "utest", "tag1", false); err != nil {
|
|
| 480 | 480 |
t.Fatal(err) |
| 481 | 481 |
} |
| 482 | 482 |
|
| 483 |
- if err := srv.runtime.repositories.Set("utest/docker", "tag2", unitTestImageName, false); err != nil {
|
|
| 483 |
+ if err := srv.ContainerTag(unitTestImageName, "utest/docker", "tag2", false); err != nil {
|
|
| 484 | 484 |
t.Fatal(err) |
| 485 | 485 |
} |
| 486 |
- if err := srv.runtime.repositories.Set("utest:5000/docker", "tag3", unitTestImageName, false); err != nil {
|
|
| 486 |
+ if err := srv.ContainerTag(unitTestImageName, "utest:5000/docker", "tag3", false); err != nil {
|
|
| 487 | 487 |
t.Fatal(err) |
| 488 | 488 |
} |
| 489 | 489 |
|
| ... | ... |
@@ -525,9 +370,9 @@ func TestImagesFilter(t *testing.T) {
|
| 525 | 525 |
} |
| 526 | 526 |
|
| 527 | 527 |
func TestImageInsert(t *testing.T) {
|
| 528 |
- runtime := mkRuntime(t) |
|
| 529 |
- defer nuke(runtime) |
|
| 530 |
- srv := &Server{runtime: runtime}
|
|
| 528 |
+ eng := NewTestEngine(t) |
|
| 529 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 530 |
+ srv := mkServerFromEngine(eng, t) |
|
| 531 | 531 |
sf := utils.NewStreamFormatter(true) |
| 532 | 532 |
|
| 533 | 533 |
// bad image name fails |
| ... | ... |
@@ -536,12 +381,12 @@ func TestImageInsert(t *testing.T) {
|
| 536 | 536 |
} |
| 537 | 537 |
|
| 538 | 538 |
// bad url fails |
| 539 |
- if err := srv.ImageInsert(GetTestImage(runtime).ID, "http://bad_host_name_that_will_totally_fail.com/", "/foo", ioutil.Discard, sf); err == nil {
|
|
| 539 |
+ if err := srv.ImageInsert(unitTestImageID, "http://bad_host_name_that_will_totally_fail.com/", "/foo", ioutil.Discard, sf); err == nil {
|
|
| 540 | 540 |
t.Fatal("expected an error and got none")
|
| 541 | 541 |
} |
| 542 | 542 |
|
| 543 | 543 |
// success returns nil |
| 544 |
- if err := srv.ImageInsert(GetTestImage(runtime).ID, "https://www.docker.io/static/img/docker-top-logo.png", "/foo", ioutil.Discard, sf); err != nil {
|
|
| 544 |
+ if err := srv.ImageInsert(unitTestImageID, "https://www.docker.io/static/img/docker-top-logo.png", "/foo", ioutil.Discard, sf); err != nil {
|
|
| 545 | 545 |
t.Fatalf("expected no error, but got %v", err)
|
| 546 | 546 |
} |
| 547 | 547 |
} |
| ... | ... |
@@ -1,26 +1,22 @@ |
| 1 | 1 |
package docker |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 4 |
+ "github.com/dotcloud/docker" |
|
| 5 |
+ "github.com/dotcloud/docker/utils" |
|
| 6 |
+ "io/ioutil" |
|
| 5 | 7 |
"testing" |
| 6 | 8 |
"time" |
| 7 | 9 |
) |
| 8 | 10 |
|
| 9 | 11 |
func TestServerListOrderedImagesByCreationDate(t *testing.T) {
|
| 10 |
- runtime := mkRuntime(t) |
|
| 11 |
- defer nuke(runtime) |
|
| 12 |
+ eng := NewTestEngine(t) |
|
| 13 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 14 |
+ srv := mkServerFromEngine(eng, t) |
|
| 12 | 15 |
|
| 13 |
- archive, err := fakeTar() |
|
| 14 |
- if err != nil {
|
|
| 15 |
- t.Fatal(err) |
|
| 16 |
- } |
|
| 17 |
- _, err = runtime.graph.Create(archive, nil, "Testing", "", nil) |
|
| 18 |
- if err != nil {
|
|
| 16 |
+ if err := generateImage("", srv); err != nil {
|
|
| 19 | 17 |
t.Fatal(err) |
| 20 | 18 |
} |
| 21 | 19 |
|
| 22 |
- srv := &Server{runtime: runtime}
|
|
| 23 |
- |
|
| 24 | 20 |
images, err := srv.Images(true, "") |
| 25 | 21 |
if err != nil {
|
| 26 | 22 |
t.Fatal(err) |
| ... | ... |
@@ -32,22 +28,22 @@ func TestServerListOrderedImagesByCreationDate(t *testing.T) {
|
| 32 | 32 |
} |
| 33 | 33 |
|
| 34 | 34 |
func TestServerListOrderedImagesByCreationDateAndTag(t *testing.T) {
|
| 35 |
- runtime := mkRuntime(t) |
|
| 36 |
- defer nuke(runtime) |
|
| 35 |
+ eng := NewTestEngine(t) |
|
| 36 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 37 |
+ srv := mkServerFromEngine(eng, t) |
|
| 37 | 38 |
|
| 38 |
- err := generateImage("bar", runtime)
|
|
| 39 |
+ err := generateImage("bar", srv)
|
|
| 39 | 40 |
if err != nil {
|
| 40 | 41 |
t.Fatal(err) |
| 41 | 42 |
} |
| 42 | 43 |
|
| 43 | 44 |
time.Sleep(time.Second) |
| 44 | 45 |
|
| 45 |
- err = generateImage("zed", runtime)
|
|
| 46 |
+ err = generateImage("zed", srv)
|
|
| 46 | 47 |
if err != nil {
|
| 47 | 48 |
t.Fatal(err) |
| 48 | 49 |
} |
| 49 | 50 |
|
| 50 |
- srv := &Server{runtime: runtime}
|
|
| 51 | 51 |
images, err := srv.Images(true, "") |
| 52 | 52 |
if err != nil {
|
| 53 | 53 |
t.Fatal(err) |
| ... | ... |
@@ -58,54 +54,10 @@ func TestServerListOrderedImagesByCreationDateAndTag(t *testing.T) {
|
| 58 | 58 |
} |
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 |
-func generateImage(name string, runtime *Runtime) error {
|
|
| 62 |
- |
|
| 61 |
+func generateImage(name string, srv *docker.Server) error {
|
|
| 63 | 62 |
archive, err := fakeTar() |
| 64 | 63 |
if err != nil {
|
| 65 | 64 |
return err |
| 66 | 65 |
} |
| 67 |
- image, err := runtime.graph.Create(archive, nil, "Testing", "", nil) |
|
| 68 |
- if err != nil {
|
|
| 69 |
- return err |
|
| 70 |
- } |
|
| 71 |
- |
|
| 72 |
- srv := &Server{runtime: runtime}
|
|
| 73 |
- srv.ContainerTag(image.ID, "repo", name, false) |
|
| 74 |
- |
|
| 75 |
- return nil |
|
| 76 |
-} |
|
| 77 |
- |
|
| 78 |
-func TestSortUniquePorts(t *testing.T) {
|
|
| 79 |
- ports := []Port{
|
|
| 80 |
- Port("6379/tcp"),
|
|
| 81 |
- Port("22/tcp"),
|
|
| 82 |
- } |
|
| 83 |
- |
|
| 84 |
- sortPorts(ports, func(ip, jp Port) bool {
|
|
| 85 |
- return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && ip.Proto() == "tcp") |
|
| 86 |
- }) |
|
| 87 |
- |
|
| 88 |
- first := ports[0] |
|
| 89 |
- if fmt.Sprint(first) != "22/tcp" {
|
|
| 90 |
- t.Log(fmt.Sprint(first)) |
|
| 91 |
- t.Fail() |
|
| 92 |
- } |
|
| 93 |
-} |
|
| 94 |
- |
|
| 95 |
-func TestSortSamePortWithDifferentProto(t *testing.T) {
|
|
| 96 |
- ports := []Port{
|
|
| 97 |
- Port("8888/tcp"),
|
|
| 98 |
- Port("8888/udp"),
|
|
| 99 |
- Port("6379/tcp"),
|
|
| 100 |
- Port("6379/udp"),
|
|
| 101 |
- } |
|
| 102 |
- |
|
| 103 |
- sortPorts(ports, func(ip, jp Port) bool {
|
|
| 104 |
- return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && ip.Proto() == "tcp") |
|
| 105 |
- }) |
|
| 106 |
- |
|
| 107 |
- first := ports[0] |
|
| 108 |
- if fmt.Sprint(first) != "6379/tcp" {
|
|
| 109 |
- t.Fail() |
|
| 110 |
- } |
|
| 66 |
+ return srv.ImageImport("-", "repo", name, archive, ioutil.Discard, utils.NewStreamFormatter(true))
|
|
| 111 | 67 |
} |
| ... | ... |
@@ -1,14 +1,15 @@ |
| 1 | 1 |
package docker |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 4 |
+ "archive/tar" |
|
| 5 |
+ "bytes" |
|
| 6 |
+ "github.com/dotcloud/docker" |
|
| 5 | 7 |
"github.com/dotcloud/docker/engine" |
| 6 | 8 |
"github.com/dotcloud/docker/utils" |
| 7 | 9 |
"io" |
| 8 | 10 |
"io/ioutil" |
| 9 | 11 |
"os" |
| 10 | 12 |
"path" |
| 11 |
- "runtime" |
|
| 12 | 13 |
"strings" |
| 13 | 14 |
"testing" |
| 14 | 15 |
) |
| ... | ... |
@@ -17,20 +18,18 @@ import ( |
| 17 | 17 |
// It has to be named XXX_test.go, apparently, in other to access private functions |
| 18 | 18 |
// from other XXX_test.go functions. |
| 19 | 19 |
|
| 20 |
-var globalTestID string |
|
| 21 |
- |
|
| 22 | 20 |
// Create a temporary runtime suitable for unit testing. |
| 23 | 21 |
// Call t.Fatal() at the first error. |
| 24 |
-func mkRuntime(f utils.Fataler) *Runtime {
|
|
| 22 |
+func mkRuntime(f utils.Fataler) *docker.Runtime {
|
|
| 25 | 23 |
root, err := newTestDirectory(unitTestStoreBase) |
| 26 | 24 |
if err != nil {
|
| 27 | 25 |
f.Fatal(err) |
| 28 | 26 |
} |
| 29 |
- config := &DaemonConfig{
|
|
| 27 |
+ config := &docker.DaemonConfig{
|
|
| 30 | 28 |
Root: root, |
| 31 | 29 |
AutoRestart: false, |
| 32 | 30 |
} |
| 33 |
- r, err := NewRuntimeFromDirectory(config) |
|
| 31 |
+ r, err := docker.NewRuntimeFromDirectory(config) |
|
| 34 | 32 |
if err != nil {
|
| 35 | 33 |
f.Fatal(err) |
| 36 | 34 |
} |
| ... | ... |
@@ -38,7 +37,7 @@ func mkRuntime(f utils.Fataler) *Runtime {
|
| 38 | 38 |
return r |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 |
-func createNamedTestContainer(eng *engine.Engine, config *Config, f utils.Fataler, name string) (shortId string) {
|
|
| 41 |
+func createNamedTestContainer(eng *engine.Engine, config *docker.Config, f utils.Fataler, name string) (shortId string) {
|
|
| 42 | 42 |
job := eng.Job("create", name)
|
| 43 | 43 |
if err := job.ImportEnv(config); err != nil {
|
| 44 | 44 |
f.Fatal(err) |
| ... | ... |
@@ -50,22 +49,34 @@ func createNamedTestContainer(eng *engine.Engine, config *Config, f utils.Fatale |
| 50 | 50 |
return |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
-func createTestContainer(eng *engine.Engine, config *Config, f utils.Fataler) (shortId string) {
|
|
| 53 |
+func createTestContainer(eng *engine.Engine, config *docker.Config, f utils.Fataler) (shortId string) {
|
|
| 54 | 54 |
return createNamedTestContainer(eng, config, f, "") |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 |
-func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *Server {
|
|
| 57 |
+func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *docker.Server {
|
|
| 58 | 58 |
iSrv := eng.Hack_GetGlobalVar("httpapi.server")
|
| 59 | 59 |
if iSrv == nil {
|
| 60 | 60 |
panic("Legacy server field not set in engine")
|
| 61 | 61 |
} |
| 62 |
- srv, ok := iSrv.(*Server) |
|
| 62 |
+ srv, ok := iSrv.(*docker.Server) |
|
| 63 | 63 |
if !ok {
|
| 64 |
- panic("Legacy server field in engine does not cast to *Server")
|
|
| 64 |
+ panic("Legacy server field in engine does not cast to *docker.Server")
|
|
| 65 | 65 |
} |
| 66 | 66 |
return srv |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 |
+func mkRuntimeFromEngine(eng *engine.Engine, t utils.Fataler) *docker.Runtime {
|
|
| 70 |
+ iRuntime := eng.Hack_GetGlobalVar("httpapi.runtime")
|
|
| 71 |
+ if iRuntime == nil {
|
|
| 72 |
+ panic("Legacy runtime field not set in engine")
|
|
| 73 |
+ } |
|
| 74 |
+ runtime, ok := iRuntime.(*docker.Runtime) |
|
| 75 |
+ if !ok {
|
|
| 76 |
+ panic("Legacy runtime field in engine does not cast to *docker.Runtime")
|
|
| 77 |
+ } |
|
| 78 |
+ return runtime |
|
| 79 |
+} |
|
| 80 |
+ |
|
| 69 | 81 |
func NewTestEngine(t utils.Fataler) *engine.Engine {
|
| 70 | 82 |
root, err := newTestDirectory(unitTestStoreBase) |
| 71 | 83 |
if err != nil {
|
| ... | ... |
@@ -87,31 +98,11 @@ func NewTestEngine(t utils.Fataler) *engine.Engine {
|
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
func newTestDirectory(templateDir string) (dir string, err error) {
|
| 90 |
- if globalTestID == "" {
|
|
| 91 |
- globalTestID = GenerateID()[:4] |
|
| 92 |
- } |
|
| 93 |
- prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, getCallerName(2))
|
|
| 94 |
- if prefix == "" {
|
|
| 95 |
- prefix = "docker-test-" |
|
| 96 |
- } |
|
| 97 |
- dir, err = ioutil.TempDir("", prefix)
|
|
| 98 |
- if err = os.Remove(dir); err != nil {
|
|
| 99 |
- return |
|
| 100 |
- } |
|
| 101 |
- if err = utils.CopyDirectory(templateDir, dir); err != nil {
|
|
| 102 |
- return |
|
| 103 |
- } |
|
| 104 |
- return |
|
| 90 |
+ return utils.TestDirectory(templateDir) |
|
| 105 | 91 |
} |
| 106 | 92 |
|
| 107 | 93 |
func getCallerName(depth int) string {
|
| 108 |
- // Use the caller function name as a prefix. |
|
| 109 |
- // This helps trace temp directories back to their test. |
|
| 110 |
- pc, _, _, _ := runtime.Caller(depth + 1) |
|
| 111 |
- callerLongName := runtime.FuncForPC(pc).Name() |
|
| 112 |
- parts := strings.Split(callerLongName, ".") |
|
| 113 |
- callerShortName := parts[len(parts)-1] |
|
| 114 |
- return callerShortName |
|
| 94 |
+ return utils.GetCallerName(depth) |
|
| 115 | 95 |
} |
| 116 | 96 |
|
| 117 | 97 |
// Write `content` to the file at path `dst`, creating it if necessary, |
| ... | ... |
@@ -152,8 +143,8 @@ func readFile(src string, t *testing.T) (content string) {
|
| 152 | 152 |
// dynamically replaced by the current test image. |
| 153 | 153 |
// The caller is responsible for destroying the container. |
| 154 | 154 |
// Call t.Fatal() at the first error. |
| 155 |
-func mkContainer(r *Runtime, args []string, t *testing.T) (*Container, error) {
|
|
| 156 |
- config, hostConfig, _, err := ParseRun(args, nil) |
|
| 155 |
+func mkContainer(r *docker.Runtime, args []string, t *testing.T) (*docker.Container, error) {
|
|
| 156 |
+ config, _, _, err := docker.ParseRun(args, nil) |
|
| 157 | 157 |
defer func() {
|
| 158 | 158 |
if err != nil && t != nil {
|
| 159 | 159 |
t.Fatal(err) |
| ... | ... |
@@ -169,7 +160,13 @@ func mkContainer(r *Runtime, args []string, t *testing.T) (*Container, error) {
|
| 169 | 169 |
if err != nil {
|
| 170 | 170 |
return nil, err |
| 171 | 171 |
} |
| 172 |
- c.hostConfig = hostConfig |
|
| 172 |
+ // NOTE: hostConfig is ignored. |
|
| 173 |
+ // If `args` specify privileged mode, custom lxc conf, external mount binds, |
|
| 174 |
+ // port redirects etc. they will be ignored. |
|
| 175 |
+ // This is because the correct way to set these things is to pass environment |
|
| 176 |
+ // to the `start` job. |
|
| 177 |
+ // FIXME: this helper function should be deprecated in favor of calling |
|
| 178 |
+ // `create` and `start` jobs directly. |
|
| 173 | 179 |
return c, nil |
| 174 | 180 |
} |
| 175 | 181 |
|
| ... | ... |
@@ -177,7 +174,7 @@ func mkContainer(r *Runtime, args []string, t *testing.T) (*Container, error) {
|
| 177 | 177 |
// and return its standard output as a string. |
| 178 | 178 |
// The image name (eg. the XXX in []string{"-i", "-t", "XXX", "bash"}, is dynamically replaced by the current test image.
|
| 179 | 179 |
// If t is not nil, call t.Fatal() at the first error. Otherwise return errors normally. |
| 180 |
-func runContainer(r *Runtime, args []string, t *testing.T) (output string, err error) {
|
|
| 180 |
+func runContainer(r *docker.Runtime, args []string, t *testing.T) (output string, err error) {
|
|
| 181 | 181 |
defer func() {
|
| 182 | 182 |
if err != nil && t != nil {
|
| 183 | 183 |
t.Fatal(err) |
| ... | ... |
@@ -205,289 +202,20 @@ func runContainer(r *Runtime, args []string, t *testing.T) (output string, err e |
| 205 | 205 |
return |
| 206 | 206 |
} |
| 207 | 207 |
|
| 208 |
-func TestCompareConfig(t *testing.T) {
|
|
| 209 |
- volumes1 := make(map[string]struct{})
|
|
| 210 |
- volumes1["/test1"] = struct{}{}
|
|
| 211 |
- config1 := Config{
|
|
| 212 |
- Dns: []string{"1.1.1.1", "2.2.2.2"},
|
|
| 213 |
- PortSpecs: []string{"1111:1111", "2222:2222"},
|
|
| 214 |
- Env: []string{"VAR1=1", "VAR2=2"},
|
|
| 215 |
- VolumesFrom: "11111111", |
|
| 216 |
- Volumes: volumes1, |
|
| 217 |
- } |
|
| 218 |
- config2 := Config{
|
|
| 219 |
- Dns: []string{"0.0.0.0", "2.2.2.2"},
|
|
| 220 |
- PortSpecs: []string{"1111:1111", "2222:2222"},
|
|
| 221 |
- Env: []string{"VAR1=1", "VAR2=2"},
|
|
| 222 |
- VolumesFrom: "11111111", |
|
| 223 |
- Volumes: volumes1, |
|
| 224 |
- } |
|
| 225 |
- config3 := Config{
|
|
| 226 |
- Dns: []string{"1.1.1.1", "2.2.2.2"},
|
|
| 227 |
- PortSpecs: []string{"0000:0000", "2222:2222"},
|
|
| 228 |
- Env: []string{"VAR1=1", "VAR2=2"},
|
|
| 229 |
- VolumesFrom: "11111111", |
|
| 230 |
- Volumes: volumes1, |
|
| 231 |
- } |
|
| 232 |
- config4 := Config{
|
|
| 233 |
- Dns: []string{"1.1.1.1", "2.2.2.2"},
|
|
| 234 |
- PortSpecs: []string{"0000:0000", "2222:2222"},
|
|
| 235 |
- Env: []string{"VAR1=1", "VAR2=2"},
|
|
| 236 |
- VolumesFrom: "22222222", |
|
| 237 |
- Volumes: volumes1, |
|
| 238 |
- } |
|
| 239 |
- volumes2 := make(map[string]struct{})
|
|
| 240 |
- volumes2["/test2"] = struct{}{}
|
|
| 241 |
- config5 := Config{
|
|
| 242 |
- Dns: []string{"1.1.1.1", "2.2.2.2"},
|
|
| 243 |
- PortSpecs: []string{"0000:0000", "2222:2222"},
|
|
| 244 |
- Env: []string{"VAR1=1", "VAR2=2"},
|
|
| 245 |
- VolumesFrom: "11111111", |
|
| 246 |
- Volumes: volumes2, |
|
| 247 |
- } |
|
| 248 |
- if CompareConfig(&config1, &config2) {
|
|
| 249 |
- t.Fatalf("CompareConfig should return false, Dns are different")
|
|
| 250 |
- } |
|
| 251 |
- if CompareConfig(&config1, &config3) {
|
|
| 252 |
- t.Fatalf("CompareConfig should return false, PortSpecs are different")
|
|
| 253 |
- } |
|
| 254 |
- if CompareConfig(&config1, &config4) {
|
|
| 255 |
- t.Fatalf("CompareConfig should return false, VolumesFrom are different")
|
|
| 256 |
- } |
|
| 257 |
- if CompareConfig(&config1, &config5) {
|
|
| 258 |
- t.Fatalf("CompareConfig should return false, Volumes are different")
|
|
| 259 |
- } |
|
| 260 |
- if !CompareConfig(&config1, &config1) {
|
|
| 261 |
- t.Fatalf("CompareConfig should return true")
|
|
| 262 |
- } |
|
| 263 |
-} |
|
| 264 |
- |
|
| 265 |
-func TestMergeConfig(t *testing.T) {
|
|
| 266 |
- volumesImage := make(map[string]struct{})
|
|
| 267 |
- volumesImage["/test1"] = struct{}{}
|
|
| 268 |
- volumesImage["/test2"] = struct{}{}
|
|
| 269 |
- configImage := &Config{
|
|
| 270 |
- Dns: []string{"1.1.1.1", "2.2.2.2"},
|
|
| 271 |
- PortSpecs: []string{"1111:1111", "2222:2222"},
|
|
| 272 |
- Env: []string{"VAR1=1", "VAR2=2"},
|
|
| 273 |
- VolumesFrom: "1111", |
|
| 274 |
- Volumes: volumesImage, |
|
| 275 |
- } |
|
| 276 |
- |
|
| 277 |
- volumesUser := make(map[string]struct{})
|
|
| 278 |
- volumesUser["/test3"] = struct{}{}
|
|
| 279 |
- configUser := &Config{
|
|
| 280 |
- Dns: []string{"3.3.3.3"},
|
|
| 281 |
- PortSpecs: []string{"3333:2222", "3333:3333"},
|
|
| 282 |
- Env: []string{"VAR2=3", "VAR3=3"},
|
|
| 283 |
- Volumes: volumesUser, |
|
| 284 |
- } |
|
| 285 |
- |
|
| 286 |
- if err := MergeConfig(configUser, configImage); err != nil {
|
|
| 287 |
- t.Error(err) |
|
| 288 |
- } |
|
| 289 |
- |
|
| 290 |
- if len(configUser.Dns) != 3 {
|
|
| 291 |
- t.Fatalf("Expected 3 dns, 1.1.1.1, 2.2.2.2 and 3.3.3.3, found %d", len(configUser.Dns))
|
|
| 292 |
- } |
|
| 293 |
- for _, dns := range configUser.Dns {
|
|
| 294 |
- if dns != "1.1.1.1" && dns != "2.2.2.2" && dns != "3.3.3.3" {
|
|
| 295 |
- t.Fatalf("Expected 1.1.1.1 or 2.2.2.2 or 3.3.3.3, found %s", dns)
|
|
| 296 |
- } |
|
| 297 |
- } |
|
| 298 |
- |
|
| 299 |
- if len(configUser.ExposedPorts) != 3 {
|
|
| 300 |
- t.Fatalf("Expected 3 ExposedPorts, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts))
|
|
| 301 |
- } |
|
| 302 |
- for portSpecs := range configUser.ExposedPorts {
|
|
| 303 |
- if portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" {
|
|
| 304 |
- t.Fatalf("Expected 1111 or 2222 or 3333, found %s", portSpecs)
|
|
| 305 |
- } |
|
| 306 |
- } |
|
| 307 |
- if len(configUser.Env) != 3 {
|
|
| 308 |
- t.Fatalf("Expected 3 env var, VAR1=1, VAR2=3 and VAR3=3, found %d", len(configUser.Env))
|
|
| 309 |
- } |
|
| 310 |
- for _, env := range configUser.Env {
|
|
| 311 |
- if env != "VAR1=1" && env != "VAR2=3" && env != "VAR3=3" {
|
|
| 312 |
- t.Fatalf("Expected VAR1=1 or VAR2=3 or VAR3=3, found %s", env)
|
|
| 313 |
- } |
|
| 314 |
- } |
|
| 315 |
- |
|
| 316 |
- if len(configUser.Volumes) != 3 {
|
|
| 317 |
- t.Fatalf("Expected 3 volumes, /test1, /test2 and /test3, found %d", len(configUser.Volumes))
|
|
| 318 |
- } |
|
| 319 |
- for v := range configUser.Volumes {
|
|
| 320 |
- if v != "/test1" && v != "/test2" && v != "/test3" {
|
|
| 321 |
- t.Fatalf("Expected /test1 or /test2 or /test3, found %s", v)
|
|
| 322 |
- } |
|
| 323 |
- } |
|
| 324 |
- |
|
| 325 |
- if configUser.VolumesFrom != "1111" {
|
|
| 326 |
- t.Fatalf("Expected VolumesFrom to be 1111, found %s", configUser.VolumesFrom)
|
|
| 327 |
- } |
|
| 328 |
- |
|
| 329 |
- ports, _, err := parsePortSpecs([]string{"0000"})
|
|
| 330 |
- if err != nil {
|
|
| 331 |
- t.Error(err) |
|
| 332 |
- } |
|
| 333 |
- configImage2 := &Config{
|
|
| 334 |
- ExposedPorts: ports, |
|
| 335 |
- } |
|
| 336 |
- |
|
| 337 |
- if err := MergeConfig(configUser, configImage2); err != nil {
|
|
| 338 |
- t.Error(err) |
|
| 339 |
- } |
|
| 340 |
- |
|
| 341 |
- if len(configUser.ExposedPorts) != 4 {
|
|
| 342 |
- t.Fatalf("Expected 4 ExposedPorts, 0000, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts))
|
|
| 343 |
- } |
|
| 344 |
- for portSpecs := range configUser.ExposedPorts {
|
|
| 345 |
- if portSpecs.Port() != "0000" && portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" {
|
|
| 346 |
- t.Fatalf("Expected 0000 or 1111 or 2222 or 3333, found %s", portSpecs)
|
|
| 347 |
- } |
|
| 348 |
- } |
|
| 349 |
- |
|
| 350 |
-} |
|
| 351 |
- |
|
| 352 |
-func TestParseLxcConfOpt(t *testing.T) {
|
|
| 353 |
- opts := []string{"lxc.utsname=docker", "lxc.utsname = docker "}
|
|
| 354 |
- |
|
| 355 |
- for _, o := range opts {
|
|
| 356 |
- k, v, err := parseLxcOpt(o) |
|
| 357 |
- if err != nil {
|
|
| 358 |
- t.FailNow() |
|
| 359 |
- } |
|
| 360 |
- if k != "lxc.utsname" {
|
|
| 361 |
- t.Fail() |
|
| 362 |
- } |
|
| 363 |
- if v != "docker" {
|
|
| 364 |
- t.Fail() |
|
| 365 |
- } |
|
| 366 |
- } |
|
| 367 |
-} |
|
| 368 |
- |
|
| 369 |
-func TestParseNetworkOptsPrivateOnly(t *testing.T) {
|
|
| 370 |
- ports, bindings, err := parsePortSpecs([]string{"192.168.1.100::80"})
|
|
| 371 |
- if err != nil {
|
|
| 372 |
- t.Fatal(err) |
|
| 373 |
- } |
|
| 374 |
- if len(ports) != 1 {
|
|
| 375 |
- t.Logf("Expected 1 got %d", len(ports))
|
|
| 376 |
- t.FailNow() |
|
| 377 |
- } |
|
| 378 |
- if len(bindings) != 1 {
|
|
| 379 |
- t.Logf("Expected 1 got %d", len(bindings))
|
|
| 380 |
- t.FailNow() |
|
| 381 |
- } |
|
| 382 |
- for k := range ports {
|
|
| 383 |
- if k.Proto() != "tcp" {
|
|
| 384 |
- t.Logf("Expected tcp got %s", k.Proto())
|
|
| 385 |
- t.Fail() |
|
| 386 |
- } |
|
| 387 |
- if k.Port() != "80" {
|
|
| 388 |
- t.Logf("Expected 80 got %s", k.Port())
|
|
| 389 |
- t.Fail() |
|
| 390 |
- } |
|
| 391 |
- b, exists := bindings[k] |
|
| 392 |
- if !exists {
|
|
| 393 |
- t.Log("Binding does not exist")
|
|
| 394 |
- t.FailNow() |
|
| 395 |
- } |
|
| 396 |
- if len(b) != 1 {
|
|
| 397 |
- t.Logf("Expected 1 got %d", len(b))
|
|
| 398 |
- t.FailNow() |
|
| 399 |
- } |
|
| 400 |
- s := b[0] |
|
| 401 |
- if s.HostPort != "" {
|
|
| 402 |
- t.Logf("Expected \"\" got %s", s.HostPort)
|
|
| 403 |
- t.Fail() |
|
| 404 |
- } |
|
| 405 |
- if s.HostIp != "192.168.1.100" {
|
|
| 406 |
- t.Fail() |
|
| 407 |
- } |
|
| 408 |
- } |
|
| 409 |
-} |
|
| 410 |
- |
|
| 411 |
-func TestParseNetworkOptsPublic(t *testing.T) {
|
|
| 412 |
- ports, bindings, err := parsePortSpecs([]string{"192.168.1.100:8080:80"})
|
|
| 413 |
- if err != nil {
|
|
| 414 |
- t.Fatal(err) |
|
| 415 |
- } |
|
| 416 |
- if len(ports) != 1 {
|
|
| 417 |
- t.Logf("Expected 1 got %d", len(ports))
|
|
| 418 |
- t.FailNow() |
|
| 419 |
- } |
|
| 420 |
- if len(bindings) != 1 {
|
|
| 421 |
- t.Logf("Expected 1 got %d", len(bindings))
|
|
| 422 |
- t.FailNow() |
|
| 423 |
- } |
|
| 424 |
- for k := range ports {
|
|
| 425 |
- if k.Proto() != "tcp" {
|
|
| 426 |
- t.Logf("Expected tcp got %s", k.Proto())
|
|
| 427 |
- t.Fail() |
|
| 428 |
- } |
|
| 429 |
- if k.Port() != "80" {
|
|
| 430 |
- t.Logf("Expected 80 got %s", k.Port())
|
|
| 431 |
- t.Fail() |
|
| 432 |
- } |
|
| 433 |
- b, exists := bindings[k] |
|
| 434 |
- if !exists {
|
|
| 435 |
- t.Log("Binding does not exist")
|
|
| 436 |
- t.FailNow() |
|
| 437 |
- } |
|
| 438 |
- if len(b) != 1 {
|
|
| 439 |
- t.Logf("Expected 1 got %d", len(b))
|
|
| 440 |
- t.FailNow() |
|
| 441 |
- } |
|
| 442 |
- s := b[0] |
|
| 443 |
- if s.HostPort != "8080" {
|
|
| 444 |
- t.Logf("Expected 8080 got %s", s.HostPort)
|
|
| 445 |
- t.Fail() |
|
| 446 |
- } |
|
| 447 |
- if s.HostIp != "192.168.1.100" {
|
|
| 448 |
- t.Fail() |
|
| 449 |
- } |
|
| 450 |
- } |
|
| 451 |
-} |
|
| 452 |
- |
|
| 453 |
-func TestParseNetworkOptsUdp(t *testing.T) {
|
|
| 454 |
- ports, bindings, err := parsePortSpecs([]string{"192.168.1.100::6000/udp"})
|
|
| 455 |
- if err != nil {
|
|
| 456 |
- t.Fatal(err) |
|
| 457 |
- } |
|
| 458 |
- if len(ports) != 1 {
|
|
| 459 |
- t.Logf("Expected 1 got %d", len(ports))
|
|
| 460 |
- t.FailNow() |
|
| 461 |
- } |
|
| 462 |
- if len(bindings) != 1 {
|
|
| 463 |
- t.Logf("Expected 1 got %d", len(bindings))
|
|
| 464 |
- t.FailNow() |
|
| 465 |
- } |
|
| 466 |
- for k := range ports {
|
|
| 467 |
- if k.Proto() != "udp" {
|
|
| 468 |
- t.Logf("Expected udp got %s", k.Proto())
|
|
| 469 |
- t.Fail() |
|
| 470 |
- } |
|
| 471 |
- if k.Port() != "6000" {
|
|
| 472 |
- t.Logf("Expected 6000 got %s", k.Port())
|
|
| 473 |
- t.Fail() |
|
| 474 |
- } |
|
| 475 |
- b, exists := bindings[k] |
|
| 476 |
- if !exists {
|
|
| 477 |
- t.Log("Binding does not exist")
|
|
| 478 |
- t.FailNow() |
|
| 479 |
- } |
|
| 480 |
- if len(b) != 1 {
|
|
| 481 |
- t.Logf("Expected 1 got %d", len(b))
|
|
| 482 |
- t.FailNow() |
|
| 483 |
- } |
|
| 484 |
- s := b[0] |
|
| 485 |
- if s.HostPort != "" {
|
|
| 486 |
- t.Logf("Expected \"\" got %s", s.HostPort)
|
|
| 487 |
- t.Fail() |
|
| 488 |
- } |
|
| 489 |
- if s.HostIp != "192.168.1.100" {
|
|
| 490 |
- t.Fail() |
|
| 208 |
+// FIXME: this is duplicated from graph_test.go in the docker package. |
|
| 209 |
+func fakeTar() (io.Reader, error) {
|
|
| 210 |
+ content := []byte("Hello world!\n")
|
|
| 211 |
+ buf := new(bytes.Buffer) |
|
| 212 |
+ tw := tar.NewWriter(buf) |
|
| 213 |
+ for _, name := range []string{"/etc/postgres/postgres.conf", "/etc/passwd", "/var/log/postgres/postgres.conf"} {
|
|
| 214 |
+ hdr := new(tar.Header) |
|
| 215 |
+ hdr.Size = int64(len(content)) |
|
| 216 |
+ hdr.Name = name |
|
| 217 |
+ if err := tw.WriteHeader(hdr); err != nil {
|
|
| 218 |
+ return nil, err |
|
| 491 | 219 |
} |
| 220 |
+ tw.Write([]byte(content)) |
|
| 492 | 221 |
} |
| 222 |
+ tw.Close() |
|
| 223 |
+ return buf, nil |
|
| 493 | 224 |
} |