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

Function GetScopesOptions

db/util_testing.go:616–645  ·  view source on GitHub ↗

GetScopesOptions sets up a ScopesOptions from a TestBucket. This will set up default or non default collections depending on the test harness use of SG_TEST_USE_DEFAULT_COLLECTION and whether the backing store supports collections.

(t testing.TB, bucket base.Bucket, numCollections int)

Source from the content-addressed store, hash-verified

614
615// GetScopesOptions sets up a ScopesOptions from a TestBucket. This will set up default or non default collections depending on the test harness use of SG_TEST_USE_DEFAULT_COLLECTION and whether the backing store supports collections.
616func GetScopesOptions(t testing.TB, bucket base.Bucket, numCollections int) ScopesOptions {
617 if !base.TestsUseNamedCollections() {
618 if numCollections != 1 {
619 t.Fatal("Setting numCollections on a test that can't use collections is invalid")
620 }
621 return GetScopesOptionsDefaultCollectionOnly(t)
622 }
623 // Get a datastore as provided by the test
624 stores := base.GetNonDefaultDatastoreNames(t, bucket)
625 require.GreaterOrEqual(t, len(stores), numCollections, "Requested more collections %d than found on testBucket %d", numCollections, len(stores))
626
627 scopesConfig := ScopesOptions{}
628 for i := 0; i < numCollections; i++ {
629 dataStoreName := stores[i]
630 if scopeConfig, ok := scopesConfig[dataStoreName.ScopeName()]; ok {
631 if _, ok := scopeConfig.Collections[dataStoreName.CollectionName()]; ok {
632 // already present
633 } else {
634 scopeConfig.Collections[dataStoreName.CollectionName()] = CollectionOptions{}
635 }
636 } else {
637 scopesConfig[dataStoreName.ScopeName()] = ScopeOptions{
638 Collections: map[string]CollectionOptions{
639 dataStoreName.CollectionName(): {},
640 }}
641 }
642
643 }
644 return scopesConfig
645}
646
647// Return Scopes options without any configuration for only the default collection.
648func GetScopesOptionsDefaultCollectionOnly(_ testing.TB) ScopesOptions {

Calls 5

TestsUseNamedCollectionsFunction · 0.92
ScopeNameMethod · 0.45
CollectionNameMethod · 0.45