MCPcopy Create free account
hub / github.com/couchbase/cbft / TestSourceNamesFromReq

Function TestSourceNamesFromReq

rest_auth_test.go:181–360  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

179}
180
181func TestSourceNamesFromReq(t *testing.T) {
182 rest.RequestProxyStubFunc = func() bool {
183 return false
184 }
185
186 emptyDir, _ := ioutil.TempDir("./tmp", "test")
187 defer func() {
188 os.RemoveAll(emptyDir)
189 rest.RequestProxyStubFunc = nil
190 }()
191
192 cfg := cbgt.NewCfgMem()
193 meh := &TestMEH{}
194 mgr := cbgt.NewManager(cbgt.VERSION, cfg, cbgt.NewUUID(),
195 nil, "", 1, "", ":1000", emptyDir, "some-datasource", meh)
196 mgr.Start("wanted")
197 mgr.Kick("test-start-kick")
198
199 mr, _ := cbgt.NewMsgRing(os.Stderr, 1000)
200
201 router, _, err := NewRESTRouter("v0", mgr, "static", "", mr, nil)
202 if err != nil || router == nil {
203 t.Errorf("no mux router")
204 }
205 router.KeepContext = true // so we can see the mux vars
206
207 s := &stubDefinitionLookuper{
208 pindexes: testPIndexesByName,
209 defs: &cbgt.IndexDefs{
210 IndexDefs: testIndexDefsByName,
211 },
212 }
213
214 tests := []struct {
215 method string
216 uri string
217 path string
218 vars map[string]string
219 sources []string
220 err error
221 }{
222 // case with valid index name
223 {
224 method: http.MethodGet,
225 uri: "/api/index/i1",
226 path: "/api/index/{indexName}",
227 vars: map[string]string{"indexName": "i1"},
228 sources: []string{"s1"},
229 },
230 // case with invalid index name
231 {
232 method: http.MethodGet,
233 uri: "/api/index/x1",
234 path: "/api/index/{indexName}",
235 vars: map[string]string{"indexName": "x1"},
236 err: errIndexNotFound,
237 },
238 // case with invalid index name (actuall pindex name)

Callers

nothing calls this directly

Calls 3

NewRESTRouterFunction · 0.85
sourceNamesFromReqFunction · 0.85
ServeHTTPMethod · 0.45

Tested by

no test coverage detected