rc: Add tests for operations/uploadfile
rc: Go import file rc_test.go
This commit is contained in:
parent
fa43d02874
commit
a2dd23efd3
1 changed files with 35 additions and 0 deletions
|
@ -4,6 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -12,6 +15,7 @@ import (
|
||||||
"github.com/rclone/rclone/fs/operations"
|
"github.com/rclone/rclone/fs/operations"
|
||||||
"github.com/rclone/rclone/fs/rc"
|
"github.com/rclone/rclone/fs/rc"
|
||||||
"github.com/rclone/rclone/fstest"
|
"github.com/rclone/rclone/fstest"
|
||||||
|
"github.com/rclone/rclone/lib/rest"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"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
|
// operations/command: Runs a backend command
|
||||||
func TestRcCommand(t *testing.T) {
|
func TestRcCommand(t *testing.T) {
|
||||||
r, call := rcNewRun(t, "backend/command")
|
r, call := rcNewRun(t, "backend/command")
|
||||||
|
|
Loading…
Reference in a new issue