Skip to content

Commit

Permalink
Merge pull request #918 from go-kivik/testSimplify
Browse files Browse the repository at this point in the history
simplify attachment checks in tests
  • Loading branch information
flimzy committed Apr 3, 2024
2 parents 016b067 + 28c259f commit b49c8bd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 124 deletions.
13 changes: 5 additions & 8 deletions x/sqlite/deleteattachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,11 @@ func TestDBDeleteAttachment(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
ContentType: "text/plain",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
},
}
Expand Down
112 changes: 44 additions & 68 deletions x/sqlite/put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ import (
)

type attachmentRow struct {
DocID string
Rev int
RevID string
Filename string
ContentType string
Digest string
Length int64
RevPos int
Stub bool
Data string
DocID string
Rev int
RevID string
Filename string
Digest string
RevPos int
Stub bool
}

func TestDBPut(t *testing.T) {
Expand Down Expand Up @@ -765,14 +762,11 @@ func TestDBPut(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
ContentType: "text/plain",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
},
})
Expand All @@ -795,14 +789,11 @@ func TestDBPut(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
ContentType: "application/octet-stream",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
},
})
Expand Down Expand Up @@ -844,24 +835,18 @@ func TestDBPut(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
ContentType: "text/plain",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
{
DocID: "foo",
RevPos: 1,
Rev: 2,
Filename: "foo.txt",
ContentType: "text/plain",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 2,
Filename: "foo.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
},
}
Expand Down Expand Up @@ -908,34 +893,25 @@ func TestDBPut(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "bar.txt",
ContentType: "text/plain",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "bar.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
ContentType: "text/plain",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
{
DocID: "foo",
RevPos: 1,
Rev: 2,
Filename: "foo.txt",
ContentType: "text/plain",
Length: 25,
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
Data: "This is a base64 encoding",
DocID: "foo",
RevPos: 1,
Rev: 2,
Filename: "foo.txt",
Digest: "md5-TmfHxaRgUrE9l3tkAn4s0Q==",
},
},
}
Expand Down Expand Up @@ -1003,7 +979,7 @@ func TestDBPut(t *testing.T) {
func checkAttachments(t *testing.T, d *sql.DB, want []attachmentRow) {
t.Helper()
rows, err := d.Query(`
SELECT b.id, b.rev, b.rev_id, a.rev_pos, a.filename, a.content_type, a.length, a.digest, a.data
SELECT b.id, b.rev, b.rev_id, a.rev_pos, a.filename, a.digest
FROM test_attachments AS a
JOIN test_attachments_bridge AS b ON b.pk=a.pk
`)
Expand All @@ -1015,7 +991,7 @@ func checkAttachments(t *testing.T, d *sql.DB, want []attachmentRow) {
for rows.Next() {
var att attachmentRow
var digest md5sum
if err := rows.Scan(&att.DocID, &att.Rev, &att.RevID, &att.RevPos, &att.Filename, &att.ContentType, &att.Length, &digest, &att.Data); err != nil {
if err := rows.Scan(&att.DocID, &att.Rev, &att.RevID, &att.RevPos, &att.Filename, &digest); err != nil {
t.Fatal(err)
}
att.Digest = digest.Digest()
Expand Down
78 changes: 30 additions & 48 deletions x/sqlite/putattachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ func TestDBPutAttachment(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
ContentType: "text/plain",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
Length: 13,
Data: "Hello, world!",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
},
},
})
Expand Down Expand Up @@ -100,14 +97,11 @@ func TestDBPutAttachment(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 2,
Rev: 2,
Filename: "foo.txt",
ContentType: "text/plain",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
Length: 13,
Data: "Hello, world!",
DocID: "foo",
RevPos: 2,
Rev: 2,
Filename: "foo.txt",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
},
},
}
Expand Down Expand Up @@ -175,24 +169,18 @@ func TestDBPutAttachment(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
ContentType: "text/plain",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
Length: 13,
Data: "Hello, world!",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
},
{
DocID: "foo",
RevPos: 2,
Rev: 2,
Filename: "bar.txt",
ContentType: "text/plain",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
Length: 13,
Data: "Hello, world!",
DocID: "foo",
RevPos: 2,
Rev: 2,
Filename: "bar.txt",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
},
},
}
Expand Down Expand Up @@ -232,24 +220,18 @@ func TestDBPutAttachment(t *testing.T) {
},
wantAttachments: []attachmentRow{
{
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
Length: 13,
ContentType: "text/plain",
Data: "Hello, world!",
DocID: "foo",
RevPos: 1,
Rev: 1,
Filename: "foo.txt",
Digest: "md5-bNNVbesNpUvKBgtMOUeYOQ==",
},
{
DocID: "foo",
RevPos: 2,
Rev: 2,
Filename: "foo.txt",
ContentType: "text/plain",
Digest: "md5-kDqL1OTtoET1YR0WdPZ5tQ==",
Length: 17,
Data: "Hello, everybody!",
DocID: "foo",
RevPos: 2,
Rev: 2,
Filename: "foo.txt",
Digest: "md5-kDqL1OTtoET1YR0WdPZ5tQ==",
},
},
}
Expand Down

0 comments on commit b49c8bd

Please sign in to comment.