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