(t *testing.T)
| 566 | } |
| 567 | |
| 568 | func 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{} |
nothing calls this directly
no test coverage detected