From 7895215606b49af10f24177eb122f7c071e9c803 Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Wed, 27 Sep 2017 22:14:59 +0300 Subject: [PATCH] Fixed sequential file upload (fixes #218) --- selenoid.go | 2 +- selenoid_test.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/selenoid.go b/selenoid.go index 2257d25a..a7654a7b 100644 --- a/selenoid.go +++ b/selenoid.go @@ -337,7 +337,7 @@ func fileUpload(w http.ResponseWriter, r *http.Request) { } defer src.Close() dir := r.Header.Get("X-Selenoid-File") - err = os.Mkdir(dir, 0755) + err = os.MkdirAll(dir, 0755) if err != nil { jsonError(w, err.Error(), http.StatusInternalServerError) return diff --git a/selenoid_test.go b/selenoid_test.go index 27ae3660..64a6ea27 100644 --- a/selenoid_test.go +++ b/selenoid_test.go @@ -442,8 +442,16 @@ func TestFileUpload(t *testing.T) { var sess map[string]string AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) - resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader([]byte(`{"file":"UEsDBBQACAgIAJiC4koAAAAAAAAAAAAAAAAJAAAAaGVsbG8udHh080jNyclXCM8vyklRBABQSwcIoxwpHA4AAAAMAAAAUEsBAhQAFAAICAgAmILiSqMcKRwOAAAADAAAAAkAAAAAAAAAAAAAAAAAAAAAAGhlbGxvLnR4dFBLBQYAAAAAAQABADcAAABFAAAAAAA="}`))) + fileContents := []byte(`{"file":"UEsDBBQACAgIAJiC4koAAAAAAAAAAAAAAAAJAAAAaGVsbG8udHh080jNyclXCM8vyklRBABQSwcIoxwpHA4AAAAMAAAAUEsBAhQAFAAICAgAmILiSqMcKRwOAAAADAAAAAkAAAAAAAAAAAAAAAAAAAAAAGhlbGxvLnR4dFBLBQYAAAAAAQABADcAAABFAAAAAAA="}`) + + //Doing two times to test sequential upload + resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader(fileContents)) + AssertThat(t, err, Is{nil}) + AssertThat(t, resp, Code{http.StatusOK}) + + resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader(fileContents)) AssertThat(t, err, Is{nil}) + AssertThat(t, resp, Code{http.StatusOK}) var jsonResponse map[string]string