MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestResyncDoesNotWriteDocBody

Function TestResyncDoesNotWriteDocBody

rest/adminapitest/resync_test.go:319–370  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

317}
318
319func TestResyncDoesNotWriteDocBody(t *testing.T) {
320 if base.UnitTestUrlIsWalrus() {
321 t.Skip("Test requires Couchbase Server")
322 }
323 base.SkipImportTestsIfNotEnabled(t) // test requires import
324
325 base.SetUpTestLogging(t, base.LevelInfo, base.KeyAll)
326 rt := rest.NewRestTester(t, &rest.RestTesterConfig{
327 PersistentConfig: true,
328 })
329 defer rt.Close()
330 docID := t.Name()
331
332 cfg := rt.NewDbConfig()
333 cfg.AutoImport = base.Ptr(false)
334 rest.RequireStatus(t, rt.CreateDatabase("db", cfg), http.StatusCreated)
335
336 collection, ctx := rt.GetSingleTestDatabaseCollectionWithUser()
337 ds := collection.GetCollectionDatastore()
338
339 specBody := []byte(`{"test":"<>"}`) // use a special character that is currently escaped to ensure it is not modified by the import process
340 _, err := ds.WriteCas(docID, 0, 0, specBody, 0)
341 require.NoError(t, err)
342
343 // trigger import
344 _, err = collection.GetDocument(ctx, docID, db.DocUnmarshalAll)
345 require.NoError(t, err)
346
347 // update sync function to have resync process the doc
348 syncFn := `
349function sync(doc, oldDoc){
350 channel("resync_channel");
351}`
352
353 resp := rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/_config/sync", syncFn)
354 rest.RequireStatus(t, resp, http.StatusOK)
355
356 // take db offline and start resync, assert that the doc is processed
357 rt.TakeDbOffline()
358
359 resp = rt.SendAdminRequest(http.MethodPost, "/{{.db}}/_resync?action=start", "")
360 rest.RequireStatus(t, resp, http.StatusOK)
361 status := rt.WaitForResyncDCPStatus(db.BackgroundProcessStateCompleted)
362 assert.Equal(t, int64(1), status.DocsChanged)
363
364 // ensure doc body remains unchanged after resync
365 collection, _ = rt.GetSingleTestDatabaseCollectionWithUser()
366 ds = collection.GetCollectionDatastore()
367 bodyGet, _, err := ds.GetRaw(docID)
368 require.NoError(t, err)
369 assert.Equal(t, string(bodyGet), string(specBody))
370}

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDbConfigMethod · 0.95
CreateDatabaseMethod · 0.95
SendAdminRequestMethod · 0.95
TakeDbOfflineMethod · 0.95
UnitTestUrlIsWalrusFunction · 0.92
SetUpTestLoggingFunction · 0.92
NewRestTesterFunction · 0.92
PtrFunction · 0.92

Tested by

no test coverage detected