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

Function TestRemoveDesignDocsUseViewsTrueAndFalse

db/design_doc_test.go:92–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

90}
91
92func 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

Callers

nothing calls this directly

Calls 11

TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
AsViewStoreFunction · 0.92
RequireAllAssertionsFunction · 0.92
assertDesignDocExistsFunction · 0.85
removeObsoleteDesignDocsFunction · 0.85
CloseMethod · 0.65
DefaultDataStoreMethod · 0.45
PutDDocMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected