Skip to content

Commit

Permalink
Missing rev
Browse files Browse the repository at this point in the history
  • Loading branch information
flimzy committed Mar 1, 2024
1 parent 0ad9fd8 commit 95e6121
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion x/sqlite/deleteattachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import (
"github.com/go-kivik/kivik/v4/internal"
)

func (d *db) DeleteAttachment(ctx context.Context, docID, filename string, _ driver.Options) (string, error) {
func (d *db) DeleteAttachment(ctx context.Context, docID, filename string, options driver.Options) (string, error) {
opts := newOpts(options)
if rev := opts.rev(); rev == "" {
return "", &internal.Error{Status: http.StatusConflict, Message: "conflict"}
}
tx, err := d.db.BeginTx(ctx, nil)
if err != nil {
return "", err
Expand Down
16 changes: 15 additions & 1 deletion x/sqlite/deleteattachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,28 @@ func TestDBDeleteAttachment(t *testing.T) {
tests.Add("doc not found", test{
docID: "foo",
filename: "foo.txt",
options: kivik.Rev("1-9bb58f26192e4ba00f01e2e7b136bbd8"),
wantErr: "document not found",
wantStatus: http.StatusNotFound,
})
tests.Add("doc exists, but no rev provided", test{
setup: func(t *testing.T, d driver.DB) {
_, err := d.Put(context.Background(), "foo", map[string]string{"foo": "bar"}, mock.NilOption)
if err != nil {
t.Fatal(err)
}
},
docID: "foo",
filename: "foo.txt",
wantErr: "conflict",
wantStatus: http.StatusConflict,
})

/*
TODO:
- db missing => db not found
- doc does not exist at specified rev => doc not found
- doc does not exist at specified rev => missing rev
- doc does exist, no rev specified => conflict
- file does not exist => file not found
*/

Expand Down

0 comments on commit 95e6121

Please sign in to comment.