Skip to content

Commit

Permalink
CBG-4271: re enable attachment tests for v4 protocol (#7144)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregns1 authored Oct 10, 2024
1 parent 122126a commit 67b2b3e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
20 changes: 7 additions & 13 deletions rest/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2254,15 +2254,14 @@ func TestAttachmentDeleteOnExpiry(t *testing.T) {
}

// TestUpdateViaBlipMigrateAttachment:
// - Tests document update through blip to a doc with attachment metadata deined in sync data
// - Tests document update through blip to a doc with attachment metadata defined in sync data
// - Assert that the c doc update this way will migrate the attachment metadata from sync data to global sync data
func TestUpdateViaBlipMigrateAttachment(t *testing.T) {
rtConfig := &RestTesterConfig{
GuestEnabled: true,
}

btcRunner := NewBlipTesterClientRunner(t)
btcRunner.SkipSubtest[VersionVectorSubtestName] = true // attachments not yet replicated in V4 protocol
const (
doc1ID = "doc1"
)
Expand All @@ -2276,7 +2275,7 @@ func TestUpdateViaBlipMigrateAttachment(t *testing.T) {
ds := rt.GetSingleDataStore()
ctx := base.TestCtx(t)

initialVersion := btc.rt.PutDoc(doc1ID, `{"_attachments": {"hello.txt": {"data": "aGVsbG8gd29ybGQ="}}}`)
initialVersion := btc.rt.PutDocWithAttachment(doc1ID, "{}", "hello.txt", "aGVsbG8gd29ybGQ=")
btc.rt.WaitForPendingChanges()
btcRunner.StartOneshotPull(btc.id)
btcRunner.WaitForVersion(btc.id, doc1ID, initialVersion)
Expand Down Expand Up @@ -2438,8 +2437,6 @@ func TestMinRevPosWorkToAvoidUnnecessaryProveAttachment(t *testing.T) {
}

btcRunner := NewBlipTesterClientRunner(t)
btcRunner.SkipSubtest[VersionVectorSubtestName] = true // CBG-4166

const docID = "doc"

btcRunner.Run(func(t *testing.T, SupportedBLIPProtocols []string) {
Expand All @@ -2450,7 +2447,7 @@ func TestMinRevPosWorkToAvoidUnnecessaryProveAttachment(t *testing.T) {
btc := btcRunner.NewBlipTesterClientOptsWithRT(rt, &opts)
defer btc.Close()
// Push an initial rev with attachment data
initialVersion := btc.rt.PutDoc(docID, `{"_attachments": {"hello.txt": {"data": "aGVsbG8gd29ybGQ="}}}`)
initialVersion := btc.rt.PutDocWithAttachment(docID, "{}", "hello.txt", "aGVsbG8gd29ybGQ=")
btc.rt.WaitForPendingChanges()

// Replicate data to client and ensure doc arrives
Expand Down Expand Up @@ -2480,8 +2477,6 @@ func TestAttachmentWithErroneousRevPos(t *testing.T) {
}

btcRunner := NewBlipTesterClientRunner(t)
btcRunner.SkipSubtest[VersionVectorSubtestName] = true // CBG-4166

btcRunner.Run(func(t *testing.T, SupportedBLIPProtocols []string) {
rt := NewRestTester(t, rtConfig)
defer rt.Close()
Expand All @@ -2492,7 +2487,7 @@ func TestAttachmentWithErroneousRevPos(t *testing.T) {
// Create rev 1 with the hello.txt attachment
const docID = "doc"

version := btc.rt.PutDoc(docID, `{"val": "val", "_attachments": {"hello.txt": {"data": "aGVsbG8gd29ybGQ="}}}`)
version := btc.rt.PutDocWithAttachment(docID, `{"val": "val"}`, "hello.txt", "aGVsbG8gd29ybGQ=")
btc.rt.WaitForPendingChanges()

// Pull rev and attachment down to client
Expand Down Expand Up @@ -2661,7 +2656,6 @@ func TestCBLRevposHandling(t *testing.T) {
}

btcRunner := NewBlipTesterClientRunner(t)
btcRunner.SkipSubtest[VersionVectorSubtestName] = true // CBG-4166
const (
doc1ID = "doc1"
doc2ID = "doc2"
Expand All @@ -2675,9 +2669,9 @@ func TestCBLRevposHandling(t *testing.T) {
btc := btcRunner.NewBlipTesterClientOptsWithRT(rt, &opts)
defer btc.Close()

doc1Version := btc.rt.PutDoc(doc1ID, `{}`)
doc2Version := btc.rt.PutDoc(doc2ID, `{}`)
btc.rt.WaitForPendingChanges()
startingBody := db.Body{"foo": "bar"}
doc1Version := btc.rt.PutDocDirectly(doc1ID, startingBody)
doc2Version := btc.rt.PutDocDirectly(doc2ID, startingBody)

btc.rt.WaitForPendingChanges()
btcRunner.StartOneshotPull(btc.id)
Expand Down
1 change: 0 additions & 1 deletion rest/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,6 @@ func createAuditLoggingRestTester(t *testing.T) *RestTester {

func TestAuditBlipCRUD(t *testing.T) {
btcRunner := NewBlipTesterClientRunner(t)
btcRunner.SkipSubtest[VersionVectorSubtestName] = true // attachments not yet replicated in V4 protocol
btcRunner.Run(func(t *testing.T, SupportedBLIPProtocols []string) {

rt := createAuditLoggingRestTester(t)
Expand Down
14 changes: 14 additions & 0 deletions rest/utilities_testing_resttester.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,17 @@ func (rt *RestTester) PutDocDirectlyInCollection(collection *db.DatabaseCollecti
require.NoError(rt.TB(), err)
return DocVersion{RevTreeID: rev, CV: db.Version{SourceID: doc.HLV.SourceID, Value: doc.HLV.Version}}
}

// PutDocWithAttachment will upsert the document with a given contents and attachments.
func (rt *RestTester) PutDocWithAttachment(docID string, body string, attachmentName, attachmentBody string) DocVersion {
// create new body with a 1.x style inline attachment body like `{"_attachments": {"camera.txt": {"data": "Q2Fub24gRU9TIDVEIE1hcmsgSVY="}}}`.
require.NotEmpty(rt.TB(), attachmentName)
require.NotEmpty(rt.TB(), attachmentBody)
var rawBody db.Body
require.NoError(rt.TB(), base.JSONUnmarshal([]byte(body), &rawBody))
require.NotContains(rt.TB(), rawBody, db.BodyAttachments)
rawBody[db.BodyAttachments] = map[string]any{
attachmentName: map[string]any{"data": attachmentBody},
}
return rt.PutDocDirectly(docID, rawBody)
}

0 comments on commit 67b2b3e

Please sign in to comment.