-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serve/restic: Disallow overwriting files in append-only mode #2196
Conversation
Hm. The failing test for AppVeyor on Windows seems to not be caused by my changes. @ncw can you please restart it? |
Very nice, and particularly the tests - not familiar with I had to add this diff --git a/cmd/serve/restic/restic_appendonly_test.go b/cmd/serve/restic/restic_appendonly_test.go
index c7ae4116..cef033e1 100644
--- a/cmd/serve/restic/restic_appendonly_test.go
+++ b/cmd/serve/restic/restic_appendonly_test.go
@@ -175,6 +175,9 @@ func TestResticHandler(t *testing.T) {
// globally set append-only mode
appendOnly = true
+ defer func() {
+ appendOnly = false // reset when done
+ }()
// make a new file system in the temp dir
f := cmd.NewFsSrc([]string{tempdir}) To make the integration tests pass too (ie where rclone calls restics REST tests). Everyone loves global variables :-( I normally use assert and require to check results from tests which are a very thin wrapper about the So if err != nil {
t.Fatal(err)
} Could become require.NoError(err) And if res.Code != code {
t.Errorf("wrong response code, want %v, got %v", code, res.Code)
} could become (note params are t, want, got) assert.Equal(t, code, res.Code) Anyway that is a minor thing and if you hate assert/require then don't bother changing them :-) |
Thanks for the comments! I'll change the few minor things you mentioned. I'm fine with whatever testing style is preferred for the project :) |
One thing that bugs me every time I see assert is that I lose the compile-time type checking. |
done, feel free to squash the commits if you like. |
FYI, the testing style is not my idea, but is derived from some tests in stdlib (obviously), in this case here: |
Yes that is certainly a slight annoyance of assert and one I've come across a few times. There are a few other little niggles too. For me, they outweight the repetitive typing though! Conceptually assert/require are very close to the standard go testing style, unlike goconvey (for instance) which always hurts my head when I have to contribute to a project using it! Thanksf or the updates - will review/merge later today when I have more time! |
Thank you very much for that - I've merged it now :-) |
This commits add tests for the HTTP handler for
rclone serve restic
in append-only mode. It is tested that files cannot be overwritten or deleted. See #2186 for some background.Closes #2195