(t *testing.T)
| 277 | } |
| 278 | |
| 279 | func TestAttachmentRetrievalUsingRevCache(t *testing.T) { |
| 280 | db, ctx := setupTestDB(t) |
| 281 | defer db.Close(ctx) |
| 282 | |
| 283 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 284 | |
| 285 | // Test creating & updating a document: |
| 286 | rev1input := `{"_attachments": {"hello.txt": {"data":"aGVsbG8gd29ybGQ="}, |
| 287 | "bye.txt": {"data":"Z29vZGJ5ZSBjcnVlbCB3b3JsZA=="}}}` |
| 288 | _, _, err := collection.Put(ctx, "doc1", unmarshalBody(t, rev1input)) |
| 289 | require.NoError(t, err, "Couldn't create document") |
| 290 | |
| 291 | initCount, countErr := base.GetExpvarAsInt("syncGateway_db", "document_gets") |
| 292 | require.NoError(t, countErr, "Couldn't retrieve document_gets expvar") |
| 293 | gotbody, err := collection.Get1xRevBody(ctx, "doc1", "1-ca9ad22802b66f662ff171f226211d5c", false, []string{}) |
| 294 | require.NoError(t, err, "Couldn't get document") |
| 295 | |
| 296 | assertAttachments := func(atts AttachmentMap) { |
| 297 | require.Equal(t, AttachmentMap{ |
| 298 | "hello.txt": DocAttachment{ |
| 299 | Data: []byte("hello world"), |
| 300 | Digest: "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", |
| 301 | Length: 11, |
| 302 | Revpos: 1, |
| 303 | }, |
| 304 | "bye.txt": DocAttachment{ |
| 305 | Data: []byte("goodbye cruel world"), |
| 306 | Digest: "sha1-l+N7VpXGnoxMm8xfvtWPbz2YvDc=", |
| 307 | Length: 19, |
| 308 | Revpos: 1, |
| 309 | }, |
| 310 | }, atts) |
| 311 | getCount, countErr := base.GetExpvarAsInt("syncGateway_db", "document_gets") |
| 312 | require.NoError(t, countErr, "Couldn't retrieve document_gets expvar") |
| 313 | require.Equal(t, initCount, getCount) |
| 314 | } |
| 315 | assertAttachments(GetAttachmentsFrom1xBody(t, gotbody)) |
| 316 | |
| 317 | // Repeat, validate no additional get operations |
| 318 | gotbody, err = collection.Get1xRevBody(ctx, "doc1", "1-ca9ad22802b66f662ff171f226211d5c", false, []string{}) |
| 319 | require.NoError(t, err, "Couldn't get document") |
| 320 | assertAttachments(GetAttachmentsFrom1xBody(t, gotbody)) |
| 321 | } |
| 322 | |
| 323 | func TestAttachmentCASRetryAfterNewAttachment(t *testing.T) { |
| 324 |
nothing calls this directly
no test coverage detected