Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Fixed sequential file upload (fixes #218)
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Sep 27, 2017
1 parent 1222c40 commit 7895215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion selenoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion selenoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7895215

Please sign in to comment.