Test for save and load commands
| ... | ... |
@@ -389,6 +389,77 @@ func TestGetContainersExport(t *testing.T) {
|
| 389 | 389 |
} |
| 390 | 390 |
} |
| 391 | 391 |
|
| 392 |
+func TestSaveImageAndThenLoad(t *testing.T) {
|
|
| 393 |
+ eng := NewTestEngine(t) |
|
| 394 |
+ defer mkRuntimeFromEngine(eng, t).Nuke() |
|
| 395 |
+ |
|
| 396 |
+ // save image |
|
| 397 |
+ r := httptest.NewRecorder() |
|
| 398 |
+ req, err := http.NewRequest("GET", "/images/"+unitTestImageID+"/get", nil)
|
|
| 399 |
+ if err != nil {
|
|
| 400 |
+ t.Fatal(err) |
|
| 401 |
+ } |
|
| 402 |
+ if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 403 |
+ t.Fatal(err) |
|
| 404 |
+ } |
|
| 405 |
+ if r.Code != http.StatusOK {
|
|
| 406 |
+ t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
|
|
| 407 |
+ } |
|
| 408 |
+ tarball := r.Body |
|
| 409 |
+ |
|
| 410 |
+ // delete the image |
|
| 411 |
+ r = httptest.NewRecorder() |
|
| 412 |
+ req, err = http.NewRequest("DELETE", "/images/"+unitTestImageID, nil)
|
|
| 413 |
+ if err != nil {
|
|
| 414 |
+ t.Fatal(err) |
|
| 415 |
+ } |
|
| 416 |
+ if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 417 |
+ t.Fatal(err) |
|
| 418 |
+ } |
|
| 419 |
+ if r.Code != http.StatusOK {
|
|
| 420 |
+ t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
|
|
| 421 |
+ } |
|
| 422 |
+ |
|
| 423 |
+ // make sure there is no image |
|
| 424 |
+ r = httptest.NewRecorder() |
|
| 425 |
+ req, err = http.NewRequest("GET", "/images/"+unitTestImageID+"/get", nil)
|
|
| 426 |
+ if err != nil {
|
|
| 427 |
+ t.Fatal(err) |
|
| 428 |
+ } |
|
| 429 |
+ if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 430 |
+ t.Fatal(err) |
|
| 431 |
+ } |
|
| 432 |
+ if r.Code != http.StatusNotFound {
|
|
| 433 |
+ t.Fatalf("%d NotFound expected, received %d\n", http.StatusNotFound, r.Code)
|
|
| 434 |
+ } |
|
| 435 |
+ |
|
| 436 |
+ // load the image |
|
| 437 |
+ r = httptest.NewRecorder() |
|
| 438 |
+ req, err = http.NewRequest("POST", "/images/load", tarball)
|
|
| 439 |
+ if err != nil {
|
|
| 440 |
+ t.Fatal(err) |
|
| 441 |
+ } |
|
| 442 |
+ if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 443 |
+ t.Fatal(err) |
|
| 444 |
+ } |
|
| 445 |
+ if r.Code != http.StatusOK {
|
|
| 446 |
+ t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
|
|
| 447 |
+ } |
|
| 448 |
+ |
|
| 449 |
+ // finally make sure the image is there |
|
| 450 |
+ r = httptest.NewRecorder() |
|
| 451 |
+ req, err = http.NewRequest("GET", "/images/"+unitTestImageID+"/get", nil)
|
|
| 452 |
+ if err != nil {
|
|
| 453 |
+ t.Fatal(err) |
|
| 454 |
+ } |
|
| 455 |
+ if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 456 |
+ t.Fatal(err) |
|
| 457 |
+ } |
|
| 458 |
+ if r.Code != http.StatusOK {
|
|
| 459 |
+ t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
|
|
| 460 |
+ } |
|
| 461 |
+} |
|
| 462 |
+ |
|
| 392 | 463 |
func TestGetContainersChanges(t *testing.T) {
|
| 393 | 464 |
eng := NewTestEngine(t) |
| 394 | 465 |
defer mkRuntimeFromEngine(eng, t).Nuke() |