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

Function TestPostWithExistingId

db/database_test.go:2601–2634  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2599}
2600
2601func TestPostWithExistingId(t *testing.T) {
2602
2603 db, ctx := setupTestDB(t)
2604 defer db.Close(ctx)
2605 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
2606
2607 // Test creating a document with existing id property:
2608 customDocId := "customIdValue"
2609 log.Printf("Create document with existing id...")
2610 body := Body{BodyId: customDocId, "key1": "value1", "key2": "existing"}
2611 docid, rev1id, _, err := collection.Post(ctx, body)
2612 require.NoError(t, err, "Couldn't create document")
2613 assert.True(t, rev1id != "")
2614 assert.True(t, docid == customDocId)
2615
2616 // Test retrieval
2617 doc, err := collection.GetDocument(ctx, customDocId, DocUnmarshalAll)
2618 assert.True(t, doc != nil)
2619 assert.NoError(t, err, "Unable to retrieve doc using custom id")
2620
2621 // Test that standard UUID creation still works:
2622 log.Printf("Create document with existing id...")
2623 body = Body{"notAnId": customDocId, "key1": "value1", "key2": "existing"}
2624 docid, rev1id, _, err = collection.Post(ctx, body)
2625 require.NoError(t, err, "Couldn't create document")
2626 assert.True(t, rev1id != "")
2627 assert.True(t, docid != customDocId)
2628
2629 // Test retrieval
2630 doc, err = collection.GetDocument(ctx, docid, DocUnmarshalAll)
2631 assert.True(t, doc != nil)
2632 assert.NoError(t, err, "Unable to retrieve doc using generated uuid")
2633
2634}
2635
2636// Unit test for issue #976
2637func TestWithNullPropertyKey(t *testing.T) {

Callers

nothing calls this directly

Calls 5

setupTestDBFunction · 0.85
PostMethod · 0.80
CloseMethod · 0.65
GetDocumentMethod · 0.65

Tested by

no test coverage detected