Docker-DCO-1.1-Signed-off-by: Adrien Folie <folie.adrien@gmail.com> (github: folieadrien)
| ... | ... |
@@ -319,6 +319,43 @@ func TestGetImagesHistory(t *testing.T) {
|
| 319 | 319 |
} |
| 320 | 320 |
} |
| 321 | 321 |
|
| 322 |
+func TestGetImagesByName(t *testing.T) {
|
|
| 323 |
+ eng := engine.New() |
|
| 324 |
+ name := "image_name" |
|
| 325 |
+ var called bool |
|
| 326 |
+ eng.Register("image_inspect", func(job *engine.Job) engine.Status {
|
|
| 327 |
+ called = true |
|
| 328 |
+ if job.Args[0] != name {
|
|
| 329 |
+ t.Fatalf("name != '%s': %#v", name, job.Args[0])
|
|
| 330 |
+ } |
|
| 331 |
+ if api.APIVERSION.LessThan("1.12") && !job.GetenvBool("dirty") {
|
|
| 332 |
+ t.Fatal("dirty env variable not set")
|
|
| 333 |
+ } else if api.APIVERSION.GreaterThanOrEqualTo("1.12") && job.GetenvBool("dirty") {
|
|
| 334 |
+ t.Fatal("dirty env variable set when it shouldn't")
|
|
| 335 |
+ } |
|
| 336 |
+ v := &engine.Env{}
|
|
| 337 |
+ v.SetBool("dirty", true)
|
|
| 338 |
+ if _, err := v.WriteTo(job.Stdout); err != nil {
|
|
| 339 |
+ return job.Error(err) |
|
| 340 |
+ } |
|
| 341 |
+ return engine.StatusOK |
|
| 342 |
+ }) |
|
| 343 |
+ r := serveRequest("GET", "/images/"+name+"/json", nil, eng, t)
|
|
| 344 |
+ if !called {
|
|
| 345 |
+ t.Fatal("handler was not called")
|
|
| 346 |
+ } |
|
| 347 |
+ if r.HeaderMap.Get("Content-Type") != "application/json" {
|
|
| 348 |
+ t.Fatalf("%#v\n", r)
|
|
| 349 |
+ } |
|
| 350 |
+ var stdoutJson interface{}
|
|
| 351 |
+ if err := json.Unmarshal(r.Body.Bytes(), &stdoutJson); err != nil {
|
|
| 352 |
+ t.Fatalf("%#v", err)
|
|
| 353 |
+ } |
|
| 354 |
+ if stdoutJson.(map[string]interface{})["dirty"].(float64) != 1 {
|
|
| 355 |
+ t.Fatalf("%#v", stdoutJson)
|
|
| 356 |
+ } |
|
| 357 |
+} |
|
| 358 |
+ |
|
| 322 | 359 |
func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t *testing.T) *httptest.ResponseRecorder {
|
| 323 | 360 |
r := httptest.NewRecorder() |
| 324 | 361 |
req, err := http.NewRequest(method, target, body) |
| 325 | 362 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os/exec" |
|
| 4 |
+ "strings" |
|
| 5 |
+ "testing" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+func TestInspectImage(t *testing.T) {
|
|
| 9 |
+ imageTest := "scratch" |
|
| 10 |
+ imageTestId := "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158" |
|
| 11 |
+ imagesCmd := exec.Command(dockerBinary, "inspect", "--format='{{.Id}}'", imageTest)
|
|
| 12 |
+ |
|
| 13 |
+ out, exitCode, err := runCommandWithOutput(imagesCmd) |
|
| 14 |
+ if exitCode != 0 || err != nil {
|
|
| 15 |
+ t.Fatalf("failed to inspect image")
|
|
| 16 |
+ } |
|
| 17 |
+ if id := strings.TrimSuffix(out, "\n"); id != imageTestId {
|
|
| 18 |
+ t.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestId, imageTest, id)
|
|
| 19 |
+ } |
|
| 20 |
+ logDone("inspect - inspect an image")
|
|
| 21 |
+} |
| ... | ... |
@@ -16,7 +16,6 @@ import ( |
| 16 | 16 |
"github.com/dotcloud/docker/api" |
| 17 | 17 |
"github.com/dotcloud/docker/api/server" |
| 18 | 18 |
"github.com/dotcloud/docker/engine" |
| 19 |
- "github.com/dotcloud/docker/image" |
|
| 20 | 19 |
"github.com/dotcloud/docker/runconfig" |
| 21 | 20 |
"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" |
| 22 | 21 |
) |
| ... | ... |
@@ -124,30 +123,6 @@ func TestGetImagesJSON(t *testing.T) {
|
| 124 | 124 |
} |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 |
-func TestGetImagesByName(t *testing.T) {
|
|
| 128 |
- eng := NewTestEngine(t) |
|
| 129 |
- defer mkDaemonFromEngine(eng, t).Nuke() |
|
| 130 |
- |
|
| 131 |
- req, err := http.NewRequest("GET", "/images/"+unitTestImageName+"/json", nil)
|
|
| 132 |
- if err != nil {
|
|
| 133 |
- t.Fatal(err) |
|
| 134 |
- } |
|
| 135 |
- |
|
| 136 |
- r := httptest.NewRecorder() |
|
| 137 |
- if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
|
|
| 138 |
- t.Fatal(err) |
|
| 139 |
- } |
|
| 140 |
- assertHttpNotError(r, t) |
|
| 141 |
- |
|
| 142 |
- img := &image.Image{}
|
|
| 143 |
- if err := json.Unmarshal(r.Body.Bytes(), img); err != nil {
|
|
| 144 |
- t.Fatal(err) |
|
| 145 |
- } |
|
| 146 |
- if img.ID != unitTestImageID {
|
|
| 147 |
- t.Errorf("Error inspecting image")
|
|
| 148 |
- } |
|
| 149 |
-} |
|
| 150 |
- |
|
| 151 | 127 |
func TestGetContainersJSON(t *testing.T) {
|
| 152 | 128 |
eng := NewTestEngine(t) |
| 153 | 129 |
defer mkDaemonFromEngine(eng, t).Nuke() |