1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Test for save and load commands

Improve test for save to tar and load from tar commands.
Docker-DCO-1.1-Signed-off-by: Fabio Falci <fabiofalci@gmail.com> (github: fabiofalci)
This commit is contained in:
Fabio Falci 2014-02-17 01:44:25 +00:00
parent 72ed2537b3
commit 4ab3c31b15

View file

@ -389,6 +389,77 @@ func TestGetContainersExport(t *testing.T) {
}
}
func TestSaveImageAndThenLoad(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()
// save image
r := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/images/"+unitTestImageID+"/get", nil)
if err != nil {
t.Fatal(err)
}
if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
if r.Code != http.StatusOK {
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
}
tarball := r.Body
// delete the image
r = httptest.NewRecorder()
req, err = http.NewRequest("DELETE", "/images/"+unitTestImageID, nil)
if err != nil {
t.Fatal(err)
}
if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
if r.Code != http.StatusOK {
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
}
// make sure there is no image
r = httptest.NewRecorder()
req, err = http.NewRequest("GET", "/images/"+unitTestImageID+"/get", nil)
if err != nil {
t.Fatal(err)
}
if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
if r.Code != http.StatusNotFound {
t.Fatalf("%d NotFound expected, received %d\n", http.StatusNotFound, r.Code)
}
// load the image
r = httptest.NewRecorder()
req, err = http.NewRequest("POST", "/images/load", tarball)
if err != nil {
t.Fatal(err)
}
if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
if r.Code != http.StatusOK {
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
}
// finally make sure the image is there
r = httptest.NewRecorder()
req, err = http.NewRequest("GET", "/images/"+unitTestImageID+"/get", nil)
if err != nil {
t.Fatal(err)
}
if err := api.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
if r.Code != http.StatusOK {
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
}
}
func TestGetContainersChanges(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()