MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestPostWithUserSpecialProperty

Function TestPostWithUserSpecialProperty

db/database_test.go:2654–2685  ·  view source on GitHub ↗

Unit test for issue #507, modified for CBG-1995 (allowing special properties)

(t *testing.T)

Source from the content-addressed store, hash-verified

2652
2653// Unit test for issue #507, modified for CBG-1995 (allowing special properties)
2654func TestPostWithUserSpecialProperty(t *testing.T) {
2655 db, ctx := setupTestDB(t)
2656 defer db.Close(ctx)
2657 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
2658
2659 // Test creating a document with existing id property:
2660 customDocId := "customIdValue"
2661 log.Printf("Create document with existing id...")
2662 body := Body{BodyId: customDocId, "key1": "value1", "key2": "existing"}
2663 docid, rev1id, _, err := collection.Post(ctx, body)
2664 require.NoError(t, err, "Couldn't create document")
2665 require.NotEqual(t, "", rev1id)
2666 require.Equal(t, customDocId, docid)
2667
2668 // Test retrieval
2669 doc, err := collection.GetDocument(ctx, customDocId, DocUnmarshalAll)
2670 require.NotNil(t, doc)
2671 assert.NoError(t, err, "Unable to retrieve doc using custom id")
2672
2673 // Test that posting an update with a user special property does update the document
2674 log.Printf("Update document with existing id...")
2675 body = Body{BodyId: customDocId, BodyRev: rev1id, "_special": "value", "key1": "value1", "key2": "existing"}
2676 rev2id, _, err := collection.Put(ctx, docid, body)
2677 assert.NoError(t, err)
2678
2679 // Test retrieval gets rev2
2680 doc, err = collection.GetDocument(ctx, docid, DocUnmarshalAll)
2681 require.NotNil(t, doc)
2682 assert.Equal(t, rev2id, doc.GetRevTreeID())
2683 assert.Equal(t, "value", doc.Body(ctx)["_special"])
2684 assert.NoError(t, err, "Unable to retrieve doc using generated uuid")
2685}
2686
2687func TestRecentSequenceHandlingForSkippedSequences(t *testing.T) {
2688 if !base.TestUseXattrs() {

Callers

nothing calls this directly

Calls 9

setupTestDBFunction · 0.85
PostMethod · 0.80
CloseMethod · 0.65
GetDocumentMethod · 0.65
PutMethod · 0.65
EqualMethod · 0.45
GetRevTreeIDMethod · 0.45
BodyMethod · 0.45

Tested by

no test coverage detected