From 3703a654056b4af7acbb09dc4d02bd184c7307c5 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 17 May 2013 17:09:09 +0000 Subject: [PATCH] fixed insert --- api_test.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++--- commands.go | 2 +- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/api_test.go b/api_test.go index 07ecc6d0bf..f77d39e3cc 100644 --- a/api_test.go +++ b/api_test.go @@ -694,10 +694,82 @@ func TestPostImagesCreate(t *testing.T) { // }) } -// func TestPostImagesInsert(t *testing.T) { -// //FIXME: Implement this test (or remove this endpoint) -// t.Log("Test not implemented") -// } +func TestPostImagesInsert(t *testing.T) { + // runtime, err := newTestRuntime() + // if err != nil { + // t.Fatal(err) + // } + // defer nuke(runtime) + + // srv := &Server{runtime: runtime} + + // stdin, stdinPipe := io.Pipe() + // stdout, stdoutPipe := io.Pipe() + + // // Attach to it + // c1 := make(chan struct{}) + // go func() { + // defer close(c1) + // r := &hijackTester{ + // ResponseRecorder: httptest.NewRecorder(), + // in: stdin, + // out: stdoutPipe, + // } + + // req, err := http.NewRequest("POST", "/images/"+unitTestImageName+"/insert?path=%2Ftest&url=https%3A%2F%2Fraw.github.com%2Fdotcloud%2Fdocker%2Fmaster%2FREADME.md", bytes.NewReader([]byte{})) + // if err != nil { + // t.Fatal(err) + // } + // if err := postContainersCreate(srv, r, req, nil); err != nil { + // t.Fatal(err) + // } + // }() + + // // Acknowledge hijack + // setTimeout(t, "hijack acknowledge timed out", 5*time.Second, func() { + // stdout.Read([]byte{}) + // stdout.Read(make([]byte, 4096)) + // }) + + // id := "" + // setTimeout(t, "Waiting for imagesInsert output", 10*time.Second, func() { + // for { + // reader := bufio.NewReader(stdout) + // id, err = reader.ReadString('\n') + // if err != nil { + // t.Fatal(err) + // } + // } + // }) + + // // Close pipes (client disconnects) + // if err := closeWrap(stdin, stdinPipe, stdout, stdoutPipe); err != nil { + // t.Fatal(err) + // } + + // // Wait for attach to finish, the client disconnected, therefore, Attach finished his job + // setTimeout(t, "Waiting for CmdAttach timed out", 2*time.Second, func() { + // <-c1 + // }) + + // img, err := srv.runtime.repositories.LookupImage(id) + // if err != nil { + // t.Fatalf("New image %s expected but not found", id) + // } + + // layer, err := img.layer() + // if err != nil { + // t.Fatal(err) + // } + + // if _, err := os.Stat(path.Join(layer, "test")); err != nil { + // t.Fatalf("The test file has not been found") + // } + + // if err := srv.runtime.graph.Delete(img.Id); err != nil { + // t.Fatal(err) + // } +} func TestPostImagesPush(t *testing.T) { //FIXME: Use staging in order to perform tests diff --git a/commands.go b/commands.go index 8734da176f..33ba8125de 100644 --- a/commands.go +++ b/commands.go @@ -104,7 +104,7 @@ func (cli *DockerCli) CmdInsert(args ...string) error { v.Set("url", cmd.Arg(1)) v.Set("path", cmd.Arg(2)) - err := cli.hijack("POST", "/images/"+cmd.Arg(0)+"?"+v.Encode(), false) + err := cli.hijack("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), false) if err != nil { return err }