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

Function TestCollectionsPutDocInKeyspace

rest/api_collections_test.go:29–114  ·  view source on GitHub ↗

TestCollectionsPutDocInKeyspace creates a collection and starts up a RestTester instance on it. Ensures that various keyspaces can or can't be used to insert a doc in the collection.

(t *testing.T)

Source from the content-addressed store, hash-verified

27// TestCollectionsPutDocInKeyspace creates a collection and starts up a RestTester instance on it.
28// Ensures that various keyspaces can or can't be used to insert a doc in the collection.
29func TestCollectionsPutDocInKeyspace(t *testing.T) {
30 const (
31 username = "alice"
32 password = "pass"
33 // dbName is the default name from RestTester
34 dbName = "db"
35 )
36 rt := NewRestTester(t, &RestTesterConfig{
37 DatabaseConfig: &DatabaseConfig{
38 DbConfig: DbConfig{
39 Users: map[string]*auth.PrincipalConfig{
40 username: {Password: base.Ptr(password)},
41 },
42 },
43 },
44 })
45 defer rt.Close()
46
47 ds := rt.GetSingleDataStore()
48 tests := []struct {
49 name string
50 keyspace string
51 expectedStatus int
52 requireCollections bool
53 }{
54 {
55 name: "fully qualified",
56 keyspace: rt.GetSingleKeyspace(),
57 expectedStatus: http.StatusCreated,
58 },
59 {
60 name: "collection only",
61 keyspace: strings.Join([]string{dbName, ds.CollectionName()}, base.ScopeCollectionSeparator),
62 expectedStatus: http.StatusCreated,
63 },
64 {
65 name: "invalid collection",
66 keyspace: strings.Join([]string{dbName, ds.ScopeName(), "buzz"}, base.ScopeCollectionSeparator),
67 expectedStatus: http.StatusNotFound,
68 },
69 {
70 name: "invalid scope",
71 keyspace: strings.Join([]string{dbName, "buzz", ds.CollectionName()}, base.ScopeCollectionSeparator),
72 expectedStatus: http.StatusNotFound,
73 },
74 {
75 name: "no default db",
76 keyspace: dbName,
77 expectedStatus: http.StatusNotFound,
78 requireCollections: true,
79 },
80 }
81
82 for i, test := range tests {
83 rt.Run(test.name, func(t *testing.T) {
84 if test.requireCollections {
85 base.TestRequiresCollections(t)
86 }

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetSingleDataStoreMethod · 0.95
GetSingleKeyspaceMethod · 0.95
RunMethod · 0.95
BucketMethod · 0.95
GetDatabaseMethod · 0.95
PtrFunction · 0.92
TestRequiresCollectionsFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
OnlyDefaultCollectionMethod · 0.80

Tested by

no test coverage detected