(t *testing.T)
| 90 | } |
| 91 | |
| 92 | func TestRemoveDesignDocsUseViewsTrueAndFalse(t *testing.T) { |
| 93 | setDesignDocPreviousVersionsForTest(t, "2.0") |
| 94 | |
| 95 | ctx := base.TestCtx(t) |
| 96 | bucket := base.GetTestBucket(t) |
| 97 | defer bucket.Close(ctx) |
| 98 | |
| 99 | mapFunction := `function (doc, meta){ emit(); }` |
| 100 | |
| 101 | viewStore, ok := base.AsViewStore(bucket.Bucket.DefaultDataStore()) |
| 102 | require.True(t, ok) |
| 103 | |
| 104 | err := viewStore.PutDDoc(ctx, DesignDocSyncGatewayPrefix+"_2.0", &sgbucket.DesignDoc{ |
| 105 | Views: sgbucket.ViewMap{ |
| 106 | "channels": sgbucket.ViewDef{Map: mapFunction}, |
| 107 | }, |
| 108 | }) |
| 109 | require.NoError(t, err) |
| 110 | err = viewStore.PutDDoc(ctx, DesignDocSyncHousekeepingPrefix+"_2.0", &sgbucket.DesignDoc{ |
| 111 | Views: sgbucket.ViewMap{ |
| 112 | "channels": sgbucket.ViewDef{Map: mapFunction}, |
| 113 | }, |
| 114 | }) |
| 115 | require.NoError(t, err) |
| 116 | err = viewStore.PutDDoc(ctx, DesignDocSyncGatewayPrefix+"_2.1", &sgbucket.DesignDoc{ |
| 117 | Views: sgbucket.ViewMap{ |
| 118 | "channels": sgbucket.ViewDef{Map: mapFunction}, |
| 119 | }, |
| 120 | }) |
| 121 | require.NoError(t, err) |
| 122 | err = viewStore.PutDDoc(ctx, DesignDocSyncHousekeepingPrefix+"_2.1", &sgbucket.DesignDoc{ |
| 123 | Views: sgbucket.ViewMap{ |
| 124 | "channels": sgbucket.ViewDef{Map: mapFunction}, |
| 125 | }, |
| 126 | }) |
| 127 | require.NoError(t, err) |
| 128 | |
| 129 | // Verify creation was successful |
| 130 | base.RequireAllAssertions(t, |
| 131 | assertDesignDocExists(t, viewStore, DesignDocSyncGatewayPrefix+"_2.0"), |
| 132 | assertDesignDocExists(t, viewStore, DesignDocSyncHousekeepingPrefix+"_2.0"), |
| 133 | assertDesignDocExists(t, viewStore, DesignDocSyncGatewayPrefix+"_2.1"), |
| 134 | assertDesignDocExists(t, viewStore, DesignDocSyncHousekeepingPrefix+"_2.1"), |
| 135 | ) |
| 136 | |
| 137 | useViewsTrueRemovalPreview := []string{"sync_gateway_2.0", "sync_housekeeping_2.0"} |
| 138 | |
| 139 | removedDDocsPreview, _ := removeObsoleteDesignDocs(ctx, viewStore, true, true) |
| 140 | assert.Equal(t, useViewsTrueRemovalPreview, removedDDocsPreview) |
| 141 | |
| 142 | useViewsFalseRemovalPreview := []string{"sync_gateway_2.0", "sync_housekeeping_2.0", "sync_gateway_2.1", "sync_housekeeping_2.1"} |
| 143 | removedDDocsPreview, _ = removeObsoleteDesignDocs(ctx, viewStore, true, false) |
| 144 | assert.Equal(t, useViewsFalseRemovalPreview, removedDDocsPreview) |
| 145 | |
| 146 | useViewsTrueRemoval := []string{"sync_gateway_2.0", "sync_housekeeping_2.0"} |
| 147 | removedDDocs, _ := removeObsoleteDesignDocs(ctx, viewStore, false, true) |
| 148 | require.Equal(t, useViewsTrueRemoval, removedDDocs) |
| 149 |
nothing calls this directly
no test coverage detected