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

Function TestCollectionsSGIndexQuery

rest/api_collections_test.go:488–544  ·  view source on GitHub ↗

TestCollectionsSGIndexQuery is more of an end-to-end test to ensure SG indexes are built correctly, and the channel access query is able to run when pulling a document as a user, and backfill the channel cache.

(t *testing.T)

Source from the content-addressed store, hash-verified

486// TestCollectionsSGIndexQuery is more of an end-to-end test to ensure SG indexes are built correctly,
487// and the channel access query is able to run when pulling a document as a user, and backfill the channel cache.
488func TestCollectionsSGIndexQuery(t *testing.T) {
489 t.Skip("Requires config-based collection channel assignment (pending CBG-2551)")
490 base.TestRequiresCollections(t)
491
492 // force GSI for this one test
493 useViews := base.Ptr(false)
494
495 const (
496 username = "alice"
497 password = "letmein"
498 validChannel = "valid"
499 invalidChannel = "invalid"
500
501 validDocID = "doc1"
502 invalidDocID = "doc2"
503 )
504
505 rt := NewRestTester(t, &RestTesterConfig{
506 DatabaseConfig: &DatabaseConfig{
507 DbConfig: DbConfig{
508 UseViews: useViews,
509 Users: map[string]*auth.PrincipalConfig{
510 username: {
511 ExplicitChannels: base.SetOf(validChannel),
512 Password: base.Ptr(password),
513 },
514 },
515 },
516 },
517 })
518 defer rt.Close()
519
520 resp := rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/"+validDocID, `{"test": true, "channels": ["`+validChannel+`"]}`)
521 RequireStatus(t, resp, http.StatusCreated)
522 resp = rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/"+invalidDocID, `{"test": true, "channels": ["`+invalidChannel+`"]}`)
523 RequireStatus(t, resp, http.StatusCreated)
524
525 resp = rt.SendUserRequestWithHeaders(http.MethodGet, "/db/_all_docs", ``, nil, username, password)
526 RequireStatus(t, resp, http.StatusOK)
527 var allDocsResponse struct {
528 TotalRows int `json:"total_rows"`
529 Rows []struct {
530 ID string `json:"id"`
531 } `json:"rows"`
532 }
533 require.NoError(t, base.JSONDecoder(resp.Body).Decode(&allDocsResponse))
534 assert.Equal(t, 1, allDocsResponse.TotalRows)
535 require.Len(t, allDocsResponse.Rows, 1)
536 assert.Equal(t, validDocID, allDocsResponse.Rows[0].ID)
537
538 resp = rt.SendUserRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/"+validDocID, ``, nil, username, password)
539 RequireStatus(t, resp, http.StatusOK)
540 resp = rt.SendUserRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/"+invalidDocID, ``, nil, username, password)
541 RequireStatus(t, resp, http.StatusForbidden)
542
543 rt.WaitForChanges(1, "/{{.keyspace}}/_changes", username, false)
544}
545

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
SendAdminRequestMethod · 0.95
WaitForChangesMethod · 0.95
TestRequiresCollectionsFunction · 0.92
PtrFunction · 0.92
SetOfFunction · 0.92
JSONDecoderFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
DecodeMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected