mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Migrate TestGetImagesHistory into unit and CLI test
Docker-DCO-1.1-Signed-off-by: Adrien Folie <folie.adrien@gmail.com> (github: folieadrien)
This commit is contained in:
parent
2075ef029e
commit
9a2771eac2
3 changed files with 45 additions and 25 deletions
|
@ -289,6 +289,33 @@ 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 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 {
|
func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t *testing.T) *httptest.ResponseRecorder {
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
req, err := http.NewRequest(method, target, body)
|
req, err := http.NewRequest(method, target, body)
|
||||||
|
|
|
@ -41,3 +41,21 @@ func TestBuildHistory(t *testing.T) {
|
||||||
|
|
||||||
deleteImages("testbuildhistory")
|
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"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"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) {
|
func TestGetImagesByName(t *testing.T) {
|
||||||
eng := NewTestEngine(t)
|
eng := NewTestEngine(t)
|
||||||
defer mkDaemonFromEngine(eng, t).Nuke()
|
defer mkDaemonFromEngine(eng, t).Nuke()
|
||||||
|
|
Loading…
Add table
Reference in a new issue