Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Fix duplicate writes, when no rev is specified at all
Browse files Browse the repository at this point in the history
  • Loading branch information
flimzy committed Jun 21, 2019
1 parent d2393cc commit f2b71c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
7 changes: 4 additions & 3 deletions put.go
Expand Up @@ -61,10 +61,11 @@ func compareRevs(doc *normalDoc, opts map[string]interface{}, currev string) err
if currev == "" {
return nil
}
if optsrev != "" && optsrev != currev {
return &kivik.Error{HTTPStatus: http.StatusConflict, Message: "document update conflict"}
newrev := optsrev
if newrev == "" {
newrev = docrev
}
if docrev != "" && docrev != currev {
if newrev != currev {
return &kivik.Error{HTTPStatus: http.StatusConflict, Message: "document update conflict"}
}
return nil
Expand Down
15 changes: 15 additions & 0 deletions put_test.go
Expand Up @@ -59,6 +59,21 @@ func TestPut(t *testing.T) {
status: http.StatusConflict,
err: "document update conflict",
})
tests.Add("duplicate", func(t *testing.T) interface{} {
doc := map[string]string{"foo": "bar"}

return tst{
id: "foo",
doc: doc,
setup: func(t *testing.T, d *db) {
if _, err := d.Put(context.Background(), "foo", doc, nil); err != nil {
t.Fatal(err)
}
},
status: http.StatusConflict,
err: "document update conflict",
}
})
tests.Add("revs mismatch", tst{
id: "foo",
doc: map[string]string{"foo": "bar", "_rev": "2-asdf"},
Expand Down
11 changes: 10 additions & 1 deletion test/fs.go
@@ -1,6 +1,8 @@
package test

import (
"net/http"

"github.com/go-kivik/kivik"
"github.com/go-kivik/kiviktest"
"github.com/go-kivik/kiviktest/kt"
Expand Down Expand Up @@ -32,6 +34,7 @@ func registerFSSuite() {
"Replicate.skip": true,

"Get.skip": true, // FIXME: Unimplemented
"GetMeta.skip": true, // FIXME: Unimplemented
"Flush.skip": true, // FIXME: Unimplemented
"Delete.skip": true, // FIXME: Unimplemented
"Stats.skip": true, // FIXME: Unimplemented
Expand All @@ -52,7 +55,13 @@ func registerFSSuite() {
"CreateIndex.skip": true, // FIXME: Unimplemented
"GetIndexes.skip": true, // FIXME: Unimplemented
"DeleteIndex.skip": true, // FIXME: Unimplemented
// "Put.skip": true, // FIXME: Unimplemented

"Put/RW/Admin/group/LeadingUnderscoreInID.status": http.StatusBadRequest,
"Put/RW/Admin/group/Conflict.status": http.StatusConflict,
"Put/RW/NoAuth/group/LeadingUnderscoreInID.status": http.StatusBadRequest,
"Put/RW/NoAuth/group/DesignDoc.status": http.StatusUnauthorized,
"Put/RW/NoAuth/group/Conflict.status": http.StatusConflict,

"SetSecurity.skip": true, // FIXME: Unimplemented
"ViewCleanup.skip": true, // FIXME: Unimplemented
"Rev.skip": true, // FIXME: Unimplemented
Expand Down

0 comments on commit f2b71c7

Please sign in to comment.