(t *testing.T, ctx context.Context, docID string, docBody []byte, attID string, attBody []byte, db *DatabaseCollectionWithUser)
| 896 | } |
| 897 | |
| 898 | func createDocWithInBodyAttachment(t *testing.T, ctx context.Context, docID string, docBody []byte, attID string, attBody []byte, db *DatabaseCollectionWithUser) string { |
| 899 | var body Body |
| 900 | err := base.JSONUnmarshal(docBody, &body) |
| 901 | assert.NoError(t, err) |
| 902 | |
| 903 | _, _, err = db.Put(ctx, docID, body) |
| 904 | assert.NoError(t, err) |
| 905 | |
| 906 | attDigest := Sha1DigestKey(attBody) |
| 907 | attDocID := MakeAttachmentKey(AttVersion1, docID, attDigest) |
| 908 | _, err = db.dataStore.AddRaw(attDocID, 0, attBody) |
| 909 | require.NoError(t, err) |
| 910 | |
| 911 | _, err = db.dataStore.Update(docID, 0, func(current []byte) (updated []byte, expiry *uint32, delete bool, err error) { |
| 912 | attachmentSyncData := map[string]interface{}{ |
| 913 | attID: map[string]interface{}{ |
| 914 | "content_type": "application/json", |
| 915 | "digest": attDigest, |
| 916 | "length": len(attBody), |
| 917 | "revpos": 2, |
| 918 | "stub": true, |
| 919 | }, |
| 920 | } |
| 921 | |
| 922 | attachmentSyncDataBytes, err := base.JSONMarshal(attachmentSyncData) |
| 923 | if err != nil { |
| 924 | return nil, base.Ptr(uint32(0)), false, err |
| 925 | } |
| 926 | |
| 927 | updated, err = base.InjectJSONPropertiesFromBytes(current, base.KVPairBytes{ |
| 928 | Key: "_attachments", |
| 929 | Val: attachmentSyncDataBytes, |
| 930 | }) |
| 931 | if err != nil { |
| 932 | return nil, base.Ptr(uint32(0)), false, err |
| 933 | } |
| 934 | |
| 935 | return updated, base.Ptr(uint32(0)), false, nil |
| 936 | }) |
| 937 | require.NoError(t, err) |
| 938 | |
| 939 | return attDocID |
| 940 | } |
| 941 | |
| 942 | // Check for regression of CBG-1980 caused by DCP closing timing issue for the mark and sweep stage |
| 943 | // May sometimes fail if docsToCreate is not high enough |
no test coverage detected