copyurl: add --auto-filename flag for using file name from url in destination path (#3451)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user