From a2dd23efd328e0ba0ae80bef0381ad1e71d225d9 Mon Sep 17 00:00:00 2001 From: Chaitanya Bankanhal Date: Thu, 18 Jun 2020 16:19:35 +0530 Subject: [PATCH] rc: Add tests for operations/uploadfile rc: Go import file rc_test.go --- fs/operations/rc_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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")