Skip to content

Commit

Permalink
Support RawJSONStream option for BuildImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
chuyeow committed Sep 8, 2014
1 parent 4c095e6 commit e0e19dc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion image.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ type BuildImageOptions struct {
ForceRmTmpContainer bool `qs:"forcerm"`
InputStream io.Reader `qs:"-"`
OutputStream io.Writer `qs:"-"`
RawJSONStream bool `qs:"-"`
Remote string `qs:"remote"`
}

Expand All @@ -322,7 +323,7 @@ func (c *Client) BuildImage(opts BuildImageOptions) error {
return ErrMissingRepo
}
return c.stream("POST", fmt.Sprintf("/build?%s",
queryString(&opts)), true, false, headers, opts.InputStream, opts.OutputStream, nil)
queryString(&opts)), true, opts.RawJSONStream, headers, opts.InputStream, opts.OutputStream, nil)
}

// TagImageOptions present the set of options to tag an image.
Expand Down
40 changes: 39 additions & 1 deletion image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func TestBuildImageParametersForRemoteBuild(t *testing.T) {
expected := map[string][]string{"t": {opts.Name}, "remote": {opts.Remote}, "q": {"1"}}
got := map[string][]string(req.URL.Query())
if !reflect.DeepEqual(got, expected) {
t.Errorf("ImportImage: wrong query string. Want %#v. Got %#v.", expected, got)
t.Errorf("BuildImage: wrong query string. Want %#v. Got %#v.", expected, got)
}
}

Expand Down Expand Up @@ -608,6 +608,44 @@ func TestBuildImageMissingOutputStream(t *testing.T) {
}
}

func TestBuildImageWithRawJSON(t *testing.T) {
body := `
{"stream":"Step 0 : FROM ubuntu:latest\n"}
{"stream":" ---\u003e 4300eb9d3c8d\n"}
{"stream":"Step 1 : MAINTAINER docker <eng@docker.com>\n"}
{"stream":" ---\u003e Using cache\n"}
{"stream":" ---\u003e 3a3ed758c370\n"}
{"stream":"Step 2 : CMD /usr/bin/top\n"}
{"stream":" ---\u003e Running in 36b1479cc2e4\n"}
{"stream":" ---\u003e 4b6188aebe39\n"}
{"stream":"Removing intermediate container 36b1479cc2e4\n"}
{"stream":"Successfully built 4b6188aebe39\n"}
`
fakeRT := &FakeRoundTripper{
message: body,
status: http.StatusOK,
header: map[string]string{
"Content-Type": "application/json",
},
}
client := newTestClient(fakeRT)
var buf bytes.Buffer
opts := BuildImageOptions{
Name: "testImage",
RmTmpContainer: true,
InputStream: &buf,
OutputStream: &buf,
RawJSONStream: true,
}
err := client.BuildImage(opts)
if err != nil {
t.Fatal(err)
}
if buf.String() != body {
t.Errorf("BuildImage: Wrong raw output. Want %q. Got %q.", body, buf.String())
}
}

func TestBuildImageRemoteWithoutName(t *testing.T) {
fakeRT := &FakeRoundTripper{message: "", status: http.StatusOK}
client := newTestClient(fakeRT)
Expand Down

0 comments on commit e0e19dc

Please sign in to comment.