Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f337a52

Browse files
committed
Move TestGetImagesByName
Docker-DCO-1.1-Signed-off-by: Adrien Folie <[email protected]> (github: folieadrien)
1 parent 8ea3589 commit f337a52

3 files changed

Lines changed: 59 additions & 25 deletions

File tree

api/server/server_unit_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,43 @@ func TestGetImagesHistory(t *testing.T) {
319319
}
320320
}
321321

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+
322359
func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t *testing.T) *httptest.ResponseRecorder {
323360
r := httptest.NewRecorder()
324361
req, err := http.NewRequest(method, target, body)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestInspectImage(t *testing.T) {
10+
imageTest := "scratch"
11+
imageTestId := "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"
12+
imagesCmd := exec.Command(dockerBinary, "inspect", "--format='{{.Id}}'", imageTest)
13+
14+
out, exitCode, err := runCommandWithOutput(imagesCmd)
15+
if exitCode != 0 || err != nil {
16+
t.Fatalf("failed to inspect image")
17+
}
18+
if id := strings.TrimSuffix(out, "\n"); id != imageTestId {
19+
t.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestId, imageTest, id)
20+
}
21+
logDone("inspect - inspect an image")
22+
}

integration/api_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/dotcloud/docker/api"
1717
"github.com/dotcloud/docker/api/server"
1818
"github.com/dotcloud/docker/engine"
19-
"github.com/dotcloud/docker/image"
2019
"github.com/dotcloud/docker/runconfig"
2120
"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
2221
)
@@ -124,30 +123,6 @@ func TestGetImagesJSON(t *testing.T) {
124123
}
125124
}
126125

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-
151126
func TestGetContainersJSON(t *testing.T) {
152127
eng := NewTestEngine(t)
153128
defer mkDaemonFromEngine(eng, t).Nuke()

0 commit comments

Comments
 (0)