Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

rc: Add tests for operations/uploadfile

Chaitanya Bankanhala2dd23efd328
diff --git a/fs/operations/rc_test.go b/fs/operations/rc_test.go
index 3f3dd99bd..7635deadb 100644
--- a/fs/operations/rc_test.go
+++ b/fs/operations/rc_test.go
@@ -4,6 +4,9 @@ import (
"context"
"net/http"
"net/http/httptest"
+ "net/url"
+ "os"
+ "path"
"testing"
"time"
@@ -12,6 +15,7 @@ import (
"github.com/rclone/rclone/fs/operations"
"github.com/rclone/rclone/fs/rc"
"github.com/rclone/rclone/fstest"
+ "github.com/rclone/rclone/lib/rest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -437,6 +441,37 @@ func TestRcFsInfo(t *testing.T) {
}
+//operations/uploadfile : Tests if upload file succeeds
+//
+func TestUploadFile(t *testing.T) {
+ r, call := rcNewRun(t, "operations/uploadfile")
+ defer r.Finalise()
+
+ testFileName := "test.txt"
+ testFileContent := "Hello World"
+ r.WriteFile(testFileName, testFileContent, t1)
+
+ currentFile, err := os.Open(path.Join(r.LocalName, testFileName))
+ require.NoError(t, err)
+
+ formReader, contentType, _, err := rest.MultipartUpload(currentFile, url.Values{}, "content", testFileName)
+ require.NoError(t, err)
+
+ httpReq := httptest.NewRequest("POST", "/", formReader)
+ httpReq.Header.Add("Content-Type", contentType)
+
+ in := rc.Params{
+ "_request": httpReq,
+ "fs": r.FremoteName,
+ "remote": "",
+ }
+
+ _, err = call.Fn(context.Background(), in)
+ require.NoError(t, err)
+
+ fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{fstest.NewItem(testFileName, testFileContent, t1)}, nil, fs.ModTimeNotSupported)
+}
+
// operations/command: Runs a backend command
func TestRcCommand(t *testing.T) {
r, call := rcNewRun(t, "backend/command")