"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
librclone: add tests for build and execute them in the actions #4891
Nick Craig-Wood62bf63d36f15
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 16f29fe1b..87990db6d 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -36,6 +36,7 @@ jobs:check: truequicktest: trueracequicktest: true+ librclonetest: truedeploy: true- job_name: mac_amd64@@ -193,6 +194,13 @@ jobs:make racequicktestif: matrix.racequicktest+ - name: Run librclone tests+ shell: bash+ run: |+ make -C librclone/ctest test+ make -C librclone/ctest clean+ if: matrix.librclonetest+- name: Code quality testshell: bashrun: |diff --git a/librclone/ctest/Makefile b/librclone/ctest/Makefileindex ae57c1739..2de219101 100644--- a/librclone/ctest/Makefile+++ b/librclone/ctest/Makefile@@ -10,5 +10,8 @@ ctest.o: ctest.c librclone.hlibrclone.a librclone.h:go build --buildmode=c-archive -o librclone.a github.com/rclone/rclone/librclone+test: ctest+ ./ctest+clean:rm -f tmp ctest *.o *.a *.h *.gchdiff --git a/librclone/ctest/ctest.c b/librclone/ctest/ctest.cindex 69c92c48e..a3ee72b26 100644--- a/librclone/ctest/ctest.c+++ b/librclone/ctest/ctest.c@@ -1,3 +1,6 @@+/*+This is a very simple test/demo program for librclone's C interface+*/#include <stdio.h>#include <stdlib.h>#include <string.h>@@ -14,21 +17,73 @@ void testRPC(char *method, char *in) {// noop commandvoid testNoOp() {printf("test rc/noop\n");- testRPC("rc/noop",- "{"+ struct RcloneRPCResult out = RcloneRPC("rc/noop", "{"" \"p1\": [1,\"2\",null,4],"" \"p2\": { \"a\":1, \"b\":2 } ""}");+ printf("status: %d\n", out.Status);+ printf("output: %s\n", out.Output);+ const char *expected =+ "{\n"+ "\t\"p1\": [\n"+ "\t\t1,\n"+ "\t\t\"2\",\n"+ "\t\tnull,\n"+ "\t\t4\n"+ "\t],\n"+ "\t\"p2\": {\n"+ "\t\t\"a\": 1,\n"+ "\t\t\"b\": 2\n"+ "\t}\n"+ "}\n";+ if (strcmp(expected, out.Output) != 0) {+ fprintf(stderr, "Wrong output.\nWant:\n%s\nGot:\n%s\n", expected, out.Output);+ exit(EXIT_FAILURE);+ }+ if (out.Status != 200) {+ fprintf(stderr, "Wrong status: want: %d: got: %d\n", 200, out.Status);+ exit(EXIT_FAILURE);+ }+ free(out.Output);}// error commandvoid testError() {printf("test rc/error\n");- testRPC("rc/error",+ struct RcloneRPCResult out = RcloneRPC("rc/error","{"" \"p1\": [1,\"2\",null,4],"" \"p2\": { \"a\":1, \"b\":2 } ""}");+ printf("status: %d\n", out.Status);+ printf("output: %s\n", out.Output);+ const char *expected =+ "{\n"+ "\t\"error\": \"arbitrary error on input map[p1:[1 2 \\u003cnil\\u003e 4] p2:map[a:1 b:2]]\",\n"+ "\t\"input\": {\n"+ "\t\t\"p1\": [\n"+ "\t\t\t1,\n"+ "\t\t\t\"2\",\n"+ "\t\t\tnull,\n"+ "\t\t\t4\n"+ "\t\t],\n"+ "\t\t\"p2\": {\n"+ "\t\t\t\"a\": 1,\n"+ "\t\t\t\"b\": 2\n"+ "\t\t}\n"+ "\t},\n"+ "\t\"path\": \"rc/error\",\n"+ "\t\"status\": 500\n"+ "}\n";+ if (strcmp(expected, out.Output) != 0) {+ fprintf(stderr, "Wrong output.\nWant:\n%s\nGot:\n%s\n", expected, out.Output);+ exit(EXIT_FAILURE);+ }+ if (out.Status != 500) {+ fprintf(stderr, "Wrong status: want: %d: got: %d\n", 500, out.Status);+ exit(EXIT_FAILURE);+ }+ free(out.Output);}// copy file using "operations/copyfile" command@@ -55,8 +110,8 @@ int main(int argc, char** argv) {testNoOp();testError();- testCopyFile();- testListRemotes();+ /* testCopyFile(); */+ /* testListRemotes(); */RcloneFinalize();return EXIT_SUCCESS;diff --git a/librclone/librclone.go b/librclone/librclone.goindex 1b6b0d4c3..40e693bee 100644--- a/librclone/librclone.go+++ b/librclone/librclone.go@@ -79,7 +79,7 @@ func RcloneFinalize() {//// Output will be returned as a serialized JSON object// Status is a HTTP status return (200=OK anything else fail)-type RcloneRPCResult struct {+type RcloneRPCResult struct { //nolint:deadcodeOutput *C.charStatus C.int}@@ -113,12 +113,12 @@ type RcloneMobileRPCResult struct {Status int}-// RcloneMobileRPCRPC this works the same as RcloneRPC but has an interface+// RcloneMobileRPC works the same as RcloneRPC but has an interface// optimised for gomobile, in particular the function signature is// valid under gobind rules.//// https://pkg.go.dev/golang.org/x/mobile/cmd/gobind#hdr-Type_restrictions-func RcloneMobileRPCRPC(method string, input string) (result RcloneMobileRPCResult) {+func RcloneMobileRPC(method string, input string) (result RcloneMobileRPCResult) { //nolint:deadcodeoutput, status := callFunctionJSON(method, input)result.Output = outputresult.Status = status