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

Function TestPostInstallCleanup

rest/view_api_test.go:568–631  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

566}
567
568func TestPostInstallCleanup(t *testing.T) {
569 rtConfig := RestTesterConfig{
570 SyncFn: `function(doc) {channel(doc.channel)}`,
571 }
572 rt := NewRestTesterDefaultCollection(t, &rtConfig)
573 defer rt.Close()
574
575 // Cleanup existing design docs
576 _, err := rt.GetDatabase().RemoveObsoleteDesignDocs(base.TestCtx(t), false)
577 require.NoError(t, err)
578
579 bucket := rt.Bucket()
580 mapFunction := `function (doc, meta) { emit(); }`
581
582 viewStore, ok := base.AsViewStore(bucket.DefaultDataStore())
583 require.True(t, ok)
584
585 // Create design docs in obsolete format
586 err = viewStore.PutDDoc(rt.Context(), db.DesignDocSyncGatewayPrefix, &sgbucket.DesignDoc{
587 Views: sgbucket.ViewMap{
588 "channels": sgbucket.ViewDef{Map: mapFunction},
589 },
590 })
591 assert.NoError(t, err, "Unable to create design doc (DesignDocSyncGatewayPrefix)")
592
593 err = viewStore.PutDDoc(rt.Context(), db.DesignDocSyncHousekeepingPrefix, &sgbucket.DesignDoc{
594 Views: sgbucket.ViewMap{
595 "all_docs": sgbucket.ViewDef{Map: mapFunction},
596 },
597 })
598 assert.NoError(t, err, "Unable to create design doc (DesignDocSyncHousekeepingPrefix)")
599
600 // Run post-upgrade in preview mode
601 var postUpgradeResponse PostUpgradeResponse
602 response := rt.SendAdminRequest(http.MethodPost, "/_post_upgrade?preview=true", "")
603 RequireStatus(t, response, http.StatusOK)
604 assert.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &postUpgradeResponse), "Error unmarshalling post_upgrade response")
605 assert.True(t, postUpgradeResponse.Preview)
606 require.Lenf(t, postUpgradeResponse.Result["db"].RemovedDDocs, 2, "Response: %#v", postUpgradeResponse)
607
608 // Run post-upgrade in non-preview mode
609 postUpgradeResponse = PostUpgradeResponse{}
610 response = rt.SendAdminRequest(http.MethodPost, "/_post_upgrade", "")
611 RequireStatus(t, response, http.StatusOK)
612 assert.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &postUpgradeResponse), "Error unmarshalling post_upgrade response")
613 assert.False(t, postUpgradeResponse.Preview)
614 require.Len(t, postUpgradeResponse.Result["db"].RemovedDDocs, 2)
615
616 // Run post-upgrade in preview mode again, expect no results for database
617 postUpgradeResponse = PostUpgradeResponse{}
618 response = rt.SendAdminRequest(http.MethodPost, "/_post_upgrade?preview=true", "")
619 RequireStatus(t, response, http.StatusOK)
620 assert.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &postUpgradeResponse), "Error unmarshalling post_upgrade response")
621 assert.True(t, postUpgradeResponse.Preview)
622 require.Len(t, postUpgradeResponse.Result["db"].RemovedDDocs, 0)
623
624 // Run post-upgrade in non-preview mode again, expect no results for database
625 postUpgradeResponse = PostUpgradeResponse{}

Callers

nothing calls this directly

Calls 14

TestCtxFunction · 0.92
AsViewStoreFunction · 0.92
JSONUnmarshalFunction · 0.92
RequireStatusFunction · 0.85
BucketMethod · 0.80
SendAdminRequestMethod · 0.80
CloseMethod · 0.65
ContextMethod · 0.65
LenMethod · 0.65
GetDatabaseMethod · 0.45

Tested by

no test coverage detected