mirror of
https://github.com/rclone/rclone.git
synced 2025-01-10 00:08:44 +01:00
copyurl: add tests for the option to honor the HTTP header filename directive
This commit is contained in:
parent
8b8802a078
commit
ac0dc9922e
@ -729,10 +729,15 @@ func TestCopyURL(t *testing.T) {
|
|||||||
|
|
||||||
// check when reading from regular HTTP server
|
// check when reading from regular HTTP server
|
||||||
status := 0
|
status := 0
|
||||||
|
nameHeader := false
|
||||||
|
headerFilename := "headerfilename.txt"
|
||||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if status != 0 {
|
if status != 0 {
|
||||||
http.Error(w, "an error ocurred", status)
|
http.Error(w, "an error ocurred", status)
|
||||||
}
|
}
|
||||||
|
if nameHeader {
|
||||||
|
w.Header().Set("Content-Disposition", `attachment; filename="folder\`+headerFilename+`"`)
|
||||||
|
}
|
||||||
_, err := w.Write([]byte(contents))
|
_, err := w.Write([]byte(contents))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
@ -757,10 +762,22 @@ func TestCopyURL(t *testing.T) {
|
|||||||
assert.Equal(t, int64(len(contents)), o.Size())
|
assert.Equal(t, int64(len(contents)), o.Size())
|
||||||
assert.Equal(t, urlFileName, o.Remote())
|
assert.Equal(t, urlFileName, o.Remote())
|
||||||
|
|
||||||
|
// Check header file naming
|
||||||
|
nameHeader = true
|
||||||
|
o, err = operations.CopyURL(ctx, r.Fremote, "", ts.URL, true, true, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, int64(len(contents)), o.Size())
|
||||||
|
assert.Equal(t, headerFilename, o.Remote())
|
||||||
|
|
||||||
// Check auto file naming when url without file name
|
// Check auto file naming when url without file name
|
||||||
_, err = operations.CopyURL(ctx, r.Fremote, "file1", ts.URL, true, false, false)
|
_, err = operations.CopyURL(ctx, r.Fremote, "file1", ts.URL, true, false, false)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
|
// Check header file naming without header set
|
||||||
|
nameHeader = false
|
||||||
|
_, err = operations.CopyURL(ctx, r.Fremote, "file1", ts.URL, true, true, false)
|
||||||
|
require.Error(t, err)
|
||||||
|
|
||||||
// Check an error is returned for a 404
|
// Check an error is returned for a 404
|
||||||
status = http.StatusNotFound
|
status = http.StatusNotFound
|
||||||
o, err = operations.CopyURL(ctx, r.Fremote, "file1", ts.URL, false, false, false)
|
o, err = operations.CopyURL(ctx, r.Fremote, "file1", ts.URL, false, false, false)
|
||||||
@ -779,7 +796,7 @@ func TestCopyURL(t *testing.T) {
|
|||||||
o, err = operations.CopyURL(ctx, r.Fremote, "file2", tss.URL, false, false, false)
|
o, err = operations.CopyURL(ctx, r.Fremote, "file2", tss.URL, false, false, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, int64(len(contents)), o.Size())
|
assert.Equal(t, int64(len(contents)), o.Size())
|
||||||
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2, fstest.NewItem(urlFileName, contents, t1)}, nil, fs.ModTimeNotSupported)
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2, fstest.NewItem(urlFileName, contents, t1), fstest.NewItem(headerFilename, contents, t1)}, nil, fs.ModTimeNotSupported)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCopyURLToWriter(t *testing.T) {
|
func TestCopyURLToWriter(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user