mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #6763 from folieadrien/master
Migrate TestGetImagesHistory into unit and CLI test
This commit is contained in:
commit
deb57c5144
3 changed files with 48 additions and 25 deletions
|
@ -289,6 +289,36 @@ func TestLogsNoStreams(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetImagesHistory(t *testing.T) {
|
||||
eng := engine.New()
|
||||
imageName := "docker-test-image"
|
||||
var called bool
|
||||
eng.Register("history", func(job *engine.Job) engine.Status {
|
||||
called = true
|
||||
if len(job.Args) == 0 {
|
||||
t.Fatal("Job arguments is empty")
|
||||
}
|
||||
if job.Args[0] != imageName {
|
||||
t.Fatalf("name != '%s': %#v", imageName, job.Args[0])
|
||||
}
|
||||
v := &engine.Env{}
|
||||
if _, err := v.WriteTo(job.Stdout); err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
return engine.StatusOK
|
||||
})
|
||||
r := serveRequest("GET", "/images/"+imageName+"/history", nil, eng, t)
|
||||
if !called {
|
||||
t.Fatalf("handler was not called")
|
||||
}
|
||||
if r.Code != http.StatusOK {
|
||||
t.Fatalf("Got status %d, expected %d", r.Code, http.StatusOK)
|
||||
}
|
||||
if r.HeaderMap.Get("Content-Type") != "application/json" {
|
||||
t.Fatalf("%#v\n", r)
|
||||
}
|
||||
}
|
||||
|
||||
func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t *testing.T) *httptest.ResponseRecorder {
|
||||
r := httptest.NewRecorder()
|
||||
req, err := http.NewRequest(method, target, body)
|
||||
|
|
|
@ -41,3 +41,21 @@ func TestBuildHistory(t *testing.T) {
|
|||
|
||||
deleteImages("testbuildhistory")
|
||||
}
|
||||
|
||||
func TestHistoryExistentImage(t *testing.T) {
|
||||
historyCmd := exec.Command(dockerBinary, "history", "busybox")
|
||||
_, exitCode, err := runCommandWithOutput(historyCmd)
|
||||
if err != nil || exitCode != 0 {
|
||||
t.Fatal("failed to get image history")
|
||||
}
|
||||
logDone("history - history on existent image must not fail")
|
||||
}
|
||||
|
||||
func TestHistoryNonExistentImage(t *testing.T) {
|
||||
historyCmd := exec.Command(dockerBinary, "history", "testHistoryNonExistentImage")
|
||||
_, exitCode, err := runCommandWithOutput(historyCmd)
|
||||
if err == nil || exitCode == 0 {
|
||||
t.Fatal("history on a non-existent image didn't result in a non-zero exit status")
|
||||
}
|
||||
logDone("history - history on non-existent image must fail")
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
|
@ -125,30 +124,6 @@ func TestGetImagesJSON(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetImagesHistory(t *testing.T) {
|
||||
eng := NewTestEngine(t)
|
||||
defer mkDaemonFromEngine(eng, t).Nuke()
|
||||
|
||||
r := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("/images/%s/history", unitTestImageName), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertHttpNotError(r, t)
|
||||
|
||||
outs := engine.NewTable("Created", 0)
|
||||
if _, err := outs.ReadListFrom(r.Body.Bytes()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(outs.Data) != 1 {
|
||||
t.Errorf("Expected 1 line, %d found", len(outs.Data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetImagesByName(t *testing.T) {
|
||||
eng := NewTestEngine(t)
|
||||
defer mkDaemonFromEngine(eng, t).Nuke()
|
||||
|
|
Loading…
Reference in a new issue