copyurl: add --auto-filename flag for using file name from url in destination path (#3451)

This commit is contained in:
Denis
2019-09-03 17:25:19 +01:00
committed by Nick Craig-Wood
parent 5932acfee3
commit b71ac141cc
6 changed files with 74 additions and 14 deletions
+16 -4
View File
@@ -706,15 +706,27 @@ func TestCopyURL(t *testing.T) {
ts := httptest.NewServer(handler)
defer ts.Close()
o, err := operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL)
o, err := operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL, false)
require.NoError(t, err)
assert.Equal(t, int64(len(contents)), o.Size())
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, nil, fs.ModTimeNotSupported)
// Check auto file naming
status = 0
urlFileName := "filename.txt"
o, err = operations.CopyURL(context.Background(), r.Fremote, "", ts.URL+"/"+urlFileName, true)
require.NoError(t, err)
assert.Equal(t, int64(len(contents)), o.Size())
assert.Equal(t, urlFileName, o.Remote())
// Check auto file naming when url without file name
o, err = operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL, true)
require.Error(t, err)
// Check an error is returned for a 404
status = http.StatusNotFound
o, err = operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL)
o, err = operations.CopyURL(context.Background(), r.Fremote, "file1", ts.URL, false)
require.Error(t, err)
assert.Contains(t, err.Error(), "Not Found")
assert.Nil(t, o)
@@ -730,10 +742,10 @@ func TestCopyURL(t *testing.T) {
tss := httptest.NewTLSServer(handler)
defer tss.Close()
o, err = operations.CopyURL(context.Background(), r.Fremote, "file2", tss.URL)
o, err = operations.CopyURL(context.Background(), r.Fremote, "file2", tss.URL, false)
require.NoError(t, err)
assert.Equal(t, int64(len(contents)), o.Size())
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2}, nil, fs.ModTimeNotSupported)
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2, fstest.NewItem(urlFileName, contents, t1)}, nil, fs.ModTimeNotSupported)
}
func TestMoveFile(t *testing.T) {