Docker-DCO-1.1-Signed-off-by: Adrien Folie <folie.adrien@gmail.com> (github: folieadrien)
| ... | ... |
@@ -289,6 +289,33 @@ func TestLogsNoStreams(t *testing.T) {
|
| 289 | 289 |
} |
| 290 | 290 |
} |
| 291 | 291 |
|
| 292 |
+func TestGetImagesHistory(t *testing.T) {
|
|
| 293 |
+ eng := engine.New() |
|
| 294 |
+ imageName := "docker-test-image" |
|
| 295 |
+ var called bool |
|
| 296 |
+ eng.Register("history", func(job *engine.Job) engine.Status {
|
|
| 297 |
+ called = true |
|
| 298 |
+ if job.Args[0] != imageName {
|
|
| 299 |
+ t.Fatalf("name != '%s': %#v", imageName, job.Args[0])
|
|
| 300 |
+ } |
|
| 301 |
+ v := &engine.Env{}
|
|
| 302 |
+ if _, err := v.WriteTo(job.Stdout); err != nil {
|
|
| 303 |
+ return job.Error(err) |
|
| 304 |
+ } |
|
| 305 |
+ return engine.StatusOK |
|
| 306 |
+ }) |
|
| 307 |
+ r := serveRequest("GET", "/images/"+imageName+"/history", nil, eng, t)
|
|
| 308 |
+ if !called {
|
|
| 309 |
+ t.Fatalf("handler was not called")
|
|
| 310 |
+ } |
|
| 311 |
+ if r.Code != http.StatusOK {
|
|
| 312 |
+ t.Fatalf("Got status %d, expected %d", r.Code, http.StatusOK)
|
|
| 313 |
+ } |
|
| 314 |
+ if r.HeaderMap.Get("Content-Type") != "application/json" {
|
|
| 315 |
+ t.Fatalf("%#v\n", r)
|
|
| 316 |
+ } |
|
| 317 |
+} |
|
| 318 |
+ |
|
| 292 | 319 |
func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t *testing.T) *httptest.ResponseRecorder {
|
| 293 | 320 |
r := httptest.NewRecorder() |
| 294 | 321 |
req, err := http.NewRequest(method, target, body) |
| ... | ... |
@@ -41,3 +41,21 @@ func TestBuildHistory(t *testing.T) {
|
| 41 | 41 |
|
| 42 | 42 |
deleteImages("testbuildhistory")
|
| 43 | 43 |
} |
| 44 |
+ |
|
| 45 |
+func TestHistoryExistentImage(t *testing.T) {
|
|
| 46 |
+ historyCmd := exec.Command(dockerBinary, "history", "busybox") |
|
| 47 |
+ _, exitCode, err := runCommandWithOutput(historyCmd) |
|
| 48 |
+ if err != nil || exitCode != 0 {
|
|
| 49 |
+ t.Fatal("failed to get image history")
|
|
| 50 |
+ } |
|
| 51 |
+ logDone("history - history on existent image must not fail")
|
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+func TestHistoryNonExistentImage(t *testing.T) {
|
|
| 55 |
+ historyCmd := exec.Command(dockerBinary, "history", "testHistoryNonExistentImage") |
|
| 56 |
+ _, exitCode, err := runCommandWithOutput(historyCmd) |
|
| 57 |
+ if err == nil || exitCode == 0 {
|
|
| 58 |
+ t.Fatal("history on a non-existent image didn't result in a non-zero exit status")
|
|
| 59 |
+ } |
|
| 60 |
+ logDone("history - history on non-existent image must fail")
|
|
| 61 |
+} |
| ... | ... |
@@ -4,7 +4,6 @@ import ( |
| 4 | 4 |
"bufio" |
| 5 | 5 |
"bytes" |
| 6 | 6 |
"encoding/json" |
| 7 |
- "fmt" |
|
| 8 | 7 |
"io" |
| 9 | 8 |
"io/ioutil" |
| 10 | 9 |
"net" |
| ... | ... |
@@ -125,30 +124,6 @@ func TestGetImagesJSON(t *testing.T) {
|
| 125 | 125 |
} |
| 126 | 126 |
} |
| 127 | 127 |
|
| 128 |
-func TestGetImagesHistory(t *testing.T) {
|
|
| 129 |
- eng := NewTestEngine(t) |
|
| 130 |
- defer mkDaemonFromEngine(eng, t).Nuke() |
|
| 131 |
- |
|
| 132 |
- r := httptest.NewRecorder() |
|
| 133 |
- |
|
| 134 |
- req, err := http.NewRequest("GET", fmt.Sprintf("/images/%s/history", unitTestImageName), nil)
|
|
| 135 |
- if err != nil {
|
|
| 136 |
- t.Fatal(err) |
|
| 137 |
- } |
|
| 138 |
- if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 139 |
- t.Fatal(err) |
|
| 140 |
- } |
|
| 141 |
- assertHttpNotError(r, t) |
|
| 142 |
- |
|
| 143 |
- outs := engine.NewTable("Created", 0)
|
|
| 144 |
- if _, err := outs.ReadListFrom(r.Body.Bytes()); err != nil {
|
|
| 145 |
- t.Fatal(err) |
|
| 146 |
- } |
|
| 147 |
- if len(outs.Data) != 1 {
|
|
| 148 |
- t.Errorf("Expected 1 line, %d found", len(outs.Data))
|
|
| 149 |
- } |
|
| 150 |
-} |
|
| 151 |
- |
|
| 152 | 128 |
func TestGetImagesByName(t *testing.T) {
|
| 153 | 129 |
eng := NewTestEngine(t) |
| 154 | 130 |
defer mkDaemonFromEngine(eng, t).Nuke() |