mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Update tests to reflect new behavior
This commit is contained in:
parent
f29e5dc8a1
commit
6145812444
2 changed files with 20 additions and 35 deletions
53
api_test.go
53
api_test.go
|
@ -14,6 +14,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
@ -587,45 +588,29 @@ func TestPostBuild(t *testing.T) {
|
|||
|
||||
srv := &Server{runtime: runtime}
|
||||
|
||||
stdin, stdinPipe := io.Pipe()
|
||||
stdout, stdoutPipe := io.Pipe()
|
||||
imgs, err := runtime.graph.All()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beginCount := len(imgs)
|
||||
|
||||
c1 := make(chan struct{})
|
||||
go func() {
|
||||
defer close(c1)
|
||||
r := &hijackTester{
|
||||
ResponseRecorder: httptest.NewRecorder(),
|
||||
in: stdin,
|
||||
out: stdoutPipe,
|
||||
}
|
||||
|
||||
if err := postBuild(srv, r, nil, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Acknowledge hijack
|
||||
setTimeout(t, "hijack acknowledge timed out", 2*time.Second, func() {
|
||||
stdout.Read([]byte{})
|
||||
stdout.Read(make([]byte, 4096))
|
||||
})
|
||||
|
||||
setTimeout(t, "read/write assertion timed out", 2*time.Second, func() {
|
||||
if err := assertPipe("from docker-ut\n", "FROM docker-ut", stdout, stdinPipe, 15); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
// Close pipes (client disconnects)
|
||||
if err := closeWrap(stdin, stdinPipe, stdout, stdoutPipe); err != nil {
|
||||
req, err := http.NewRequest("POST", "/build", strings.NewReader(Dockerfile))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Wait for build to finish, the client disconnected, therefore, Build finished his job
|
||||
setTimeout(t, "Waiting for CmdBuild timed out", 2*time.Second, func() {
|
||||
<-c1
|
||||
})
|
||||
r := httptest.NewRecorder()
|
||||
if err := postBuild(srv, r, req, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
imgs, err = runtime.graph.All()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(imgs) != beginCount+3 {
|
||||
t.Fatalf("Expected %d images, %d found", beginCount+3, len(imgs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostImagesCreate(t *testing.T) {
|
||||
|
|
|
@ -117,7 +117,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
err := cli.stream("POST", "/build", nil, os.Stdout)
|
||||
err := cli.stream("POST", "/build", os.Stdin, os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue