TestMigrateBodyAttachmentsMerge will set up a document with attachments in both pre-2.5 and post-2.5 metadata, making sure that both attachments are preserved.
(t *testing.T)
| 1020 | |
| 1021 | // TestMigrateBodyAttachmentsMerge will set up a document with attachments in both pre-2.5 and post-2.5 metadata, making sure that both attachments are preserved. |
| 1022 | func TestMigrateBodyAttachmentsMerge(t *testing.T) { |
| 1023 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD) |
| 1024 | |
| 1025 | const docKey = "TestMigrateBodyAttachmentsMerge" |
| 1026 | |
| 1027 | db, ctx := setupTestDB(t) |
| 1028 | defer db.Close(ctx) |
| 1029 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 1030 | |
| 1031 | // Put a document 2 attachments, to write attachment to the bucket |
| 1032 | rev1input := `{"_attachments": {"hello.txt": {"data":"aGVsbG8gd29ybGQ="},"bye.txt": {"data":"Z29vZGJ5ZSBjcnVlbCB3b3JsZA=="}}}` |
| 1033 | var body Body |
| 1034 | assert.NoError(t, base.JSONUnmarshal([]byte(rev1input), &body)) |
| 1035 | _, _, err := collection.Put(ctx, "doc1", body) |
| 1036 | require.NoError(t, err, "Couldn't create document") |
| 1037 | |
| 1038 | gotbody, err := collection.Get1xRevBody(ctx, "doc1", "", false, []string{}) |
| 1039 | require.NoError(t, err) |
| 1040 | require.Equal(t, AttachmentMap{ |
| 1041 | "hello.txt": DocAttachment{ |
| 1042 | Digest: "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", |
| 1043 | Length: 11, |
| 1044 | Data: []byte("hello world"), |
| 1045 | Revpos: 1, |
| 1046 | }, |
| 1047 | "bye.txt": DocAttachment{ |
| 1048 | Digest: "sha1-l+N7VpXGnoxMm8xfvtWPbz2YvDc=", |
| 1049 | Length: 19, |
| 1050 | Data: []byte("goodbye cruel world"), |
| 1051 | Revpos: 1, |
| 1052 | }, |
| 1053 | }, GetAttachmentsFrom1xBody(t, gotbody)) |
| 1054 | |
| 1055 | // Create 2.1 style document - metadata in sync data, _attachments in body, referencing attachments created above |
| 1056 | bodyPre25 := `{ |
| 1057 | "test":true, |
| 1058 | "_attachments": { |
| 1059 | "hello.txt": { |
| 1060 | "digest": "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", |
| 1061 | "length": 11, |
| 1062 | "revpos": 1, |
| 1063 | "stub": true |
| 1064 | } |
| 1065 | } |
| 1066 | }` |
| 1067 | |
| 1068 | syncData := `{ |
| 1069 | "rev": "3-a", |
| 1070 | "sequence": 4, |
| 1071 | "recent_sequences": [ |
| 1072 | 4 |
| 1073 | ], |
| 1074 | "history": { |
| 1075 | "revs": [ |
| 1076 | "2-a", |
| 1077 | "3-a", |
| 1078 | "1-a" |
| 1079 | ], |
nothing calls this directly
no test coverage detected