TestMigrateBodyAttachments will set up a document with an attachment in pre-2.5 metadata format, and test various upgrade scenarios.
(t *testing.T)
| 770 | |
| 771 | // TestMigrateBodyAttachments will set up a document with an attachment in pre-2.5 metadata format, and test various upgrade scenarios. |
| 772 | func TestMigrateBodyAttachments(t *testing.T) { |
| 773 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
| 774 | |
| 775 | const docKey = "TestMigrateBodyAttachments" |
| 776 | |
| 777 | setupFn := func(t *testing.T) (db *Database, ctx context.Context) { |
| 778 | db, ctx = setupTestDB(t) |
| 779 | |
| 780 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 781 | |
| 782 | // Create 2.1 style document - metadata in sync data, _attachments in body, referencing attachment created above |
| 783 | bodyPre25 := `{ |
| 784 | "test":true, |
| 785 | "_attachments": { |
| 786 | "hello.txt": { |
| 787 | "digest": "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", |
| 788 | "length": 11, |
| 789 | "revpos": 1, |
| 790 | "stub": true |
| 791 | } |
| 792 | } |
| 793 | }` |
| 794 | |
| 795 | syncData := `{ |
| 796 | "rev": "3-a", |
| 797 | "sequence": 4, |
| 798 | "recent_sequences": [ |
| 799 | 4 |
| 800 | ], |
| 801 | "history": { |
| 802 | "revs": [ |
| 803 | "2-a", |
| 804 | "3-a", |
| 805 | "1-a" |
| 806 | ], |
| 807 | "parents": [ |
| 808 | 2, |
| 809 | 0, |
| 810 | -1 |
| 811 | ], |
| 812 | "channels": [ |
| 813 | [ |
| 814 | "ABC" |
| 815 | ], |
| 816 | [ |
| 817 | "ABC" |
| 818 | ], |
| 819 | [ |
| 820 | "ABC" |
| 821 | ] |
| 822 | ] |
| 823 | }, |
| 824 | "channels": { |
| 825 | "ABC": null |
| 826 | } |
| 827 | }` |
| 828 | |
| 829 | _, err := collection.dataStore.WriteWithXattrs(ctx, docKey, 0, 0, []byte(bodyPre25), map[string][]byte{base.SyncXattrName: []byte(syncData)}, nil, DefaultMutateInOpts()) |
nothing calls this directly
no test coverage detected