(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func TestAttachments(t *testing.T) { |
| 146 | |
| 147 | db, ctx := setupTestDBAllowConflicts(t) |
| 148 | defer db.Close(ctx) |
| 149 | |
| 150 | // Test creating & updating a document: |
| 151 | log.Printf("Create rev 1...") |
| 152 | rev1input := `{"_attachments": {"hello.txt": {"data":"aGVsbG8gd29ybGQ="}, |
| 153 | "bye.txt": {"data":"Z29vZGJ5ZSBjcnVlbCB3b3JsZA=="}}}` |
| 154 | var body Body |
| 155 | assert.NoError(t, base.JSONUnmarshal([]byte(rev1input), &body)) |
| 156 | |
| 157 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 158 | rev1id, _, err := collection.Put(ctx, "doc1", body) |
| 159 | require.NoError(t, err) |
| 160 | |
| 161 | log.Printf("Retrieve doc...") |
| 162 | gotbody, err := collection.Get1xRevBody(ctx, "doc1", "", false, []string{}) |
| 163 | require.NoError(t, err) |
| 164 | atts := GetAttachmentsFrom1xBody(t, gotbody) |
| 165 | require.Equal(t, AttachmentMap{ |
| 166 | "hello.txt": DocAttachment{ |
| 167 | Data: []byte("hello world"), |
| 168 | Digest: "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", |
| 169 | Length: 11, |
| 170 | Revpos: 1, |
| 171 | }, |
| 172 | "bye.txt": DocAttachment{ |
| 173 | Data: []byte("goodbye cruel world"), |
| 174 | Digest: "sha1-l+N7VpXGnoxMm8xfvtWPbz2YvDc=", |
| 175 | Length: 19, |
| 176 | Revpos: 1, |
| 177 | }, |
| 178 | }, atts) |
| 179 | log.Printf("Create rev 2...") |
| 180 | rev2str := `{"_attachments": {"hello.txt": {"stub":true, "revpos":1}, "bye.txt": {"data": "YnllLXlh"}}}` |
| 181 | var body2 Body |
| 182 | assert.NoError(t, base.JSONUnmarshal([]byte(rev2str), &body2)) |
| 183 | body2[BodyRev] = rev1id |
| 184 | rev2id, _, err := collection.Put(ctx, "doc1", body2) |
| 185 | require.NoError(t, err, "Couldn't update document") |
| 186 | assert.Equal(t, "2-5d3308aae9930225ed7f6614cf115366", rev2id) |
| 187 | |
| 188 | log.Printf("Retrieve doc...") |
| 189 | gotbody, err = collection.Get1xRevBody(ctx, "doc1", "", false, []string{}) |
| 190 | require.NoError(t, err) |
| 191 | atts = GetAttachmentsFrom1xBody(t, gotbody) |
| 192 | require.Equal(t, AttachmentMap{ |
| 193 | "hello.txt": DocAttachment{ |
| 194 | Data: []byte("hello world"), |
| 195 | Digest: "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", |
| 196 | Length: 11, |
| 197 | Revpos: 1, |
| 198 | }, |
| 199 | "bye.txt": DocAttachment{ |
| 200 | Data: []byte("bye-ya"), |
| 201 | Digest: "sha1-gwwPApfQR9bzBKpqoEYwFmKp98A=", |
| 202 | Length: 6, |
nothing calls this directly
no test coverage detected