Skip to content

Commit

Permalink
add tests on downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain committed Jan 31, 2017
1 parent 767d3fb commit 322de40
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ Content-Disposition: attachment; filename="project-X.zip"
Content-Type: application/zip
```

### POST /files/downloads/?Path=file_path
### POST /files/downloads?Path=file_path

Create a file download. The Path query parameter specifies the file to download.
The response json API links contains a `related` link for downloading the file, see below.
Expand Down
26 changes: 26 additions & 0 deletions web/files/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,32 @@ func TestArchiveCreateAndDownload(t *testing.T) {
assert.Equal(t, `attachment; filename=archive.zip`, disposition)
}

func TestFileCreateAndDownload(t *testing.T) {

body := "foo,bar"
res1, _ := upload(t, "/files/?Type=file&Name=todownload2steps", "text/plain", body, "UmfjCVWct/albVkURcJJfg==")
if !assert.Equal(t, 201, res1.StatusCode) {
return
}

path := "/todownload2steps"

res, err := http.Post(ts.URL+"/files/downloads?Path="+path, "", nil)
assert.NoError(t, err)
assert.Equal(t, 200, res.StatusCode)
var data map[string]interface{}
err = json.NewDecoder(res.Body).Decode(&data)
fmt.Println(&data, err)
assert.NoError(t, err)

downloadURL := ts.URL + data["links"].(map[string]interface{})["related"].(string)
res2, err := http.Get(downloadURL)
assert.NoError(t, err)
assert.Equal(t, 200, res2.StatusCode)
disposition := res2.Header.Get("Content-Disposition")
assert.Equal(t, `attachment; filename=todownload2steps`, disposition)
}

func TestArchiveNotFound(t *testing.T) {
body := bytes.NewBufferString(`{
"data": {
Expand Down

0 comments on commit 322de40

Please sign in to comment.