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

Function TestBootstrapDuplicateDatabase

rest/bootstrap_test.go:149–186  ·  view source on GitHub ↗

TestBootstrapDuplicateDatabase will attempt to create a second database and ensure this isn't allowed.

(t *testing.T)

Source from the content-addressed store, hash-verified

147
148// TestBootstrapDuplicateDatabase will attempt to create a second database and ensure this isn't allowed.
149func TestBootstrapDuplicateDatabase(t *testing.T) {
150 base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP)
151
152 sc, closeFn := StartBootstrapServer(t)
153 defer closeFn()
154
155 // Get a test bucket, and use it to create the database.
156 ctx := base.TestCtx(t)
157 tb := base.GetTestBucket(t)
158 defer tb.Close(ctx)
159
160 dbConfig := fmt.Sprintf(
161 `{"bucket": "%s", "num_index_replicas": 0, "enable_shared_bucket_access": %t, "use_views": %t}`,
162 tb.GetName(), base.TestUseXattrs(), base.TestsDisableGSI(),
163 )
164
165 resp := BootstrapAdminRequest(t, sc, http.MethodPut, "/db1/", dbConfig)
166 resp.RequireStatus(http.StatusCreated)
167
168 // Write a doc, we'll rely on it for later stat assertions to ensure the database isn't being reloaded.
169 resp = BootstrapAdminRequest(t, sc, http.MethodPut, "/db1/doc1", `{"test": true}`)
170 resp.RequireStatus(http.StatusCreated)
171
172 // check to see we have a doc written stat
173 resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/_expvar", "")
174 resp.RequireStatus(http.StatusOK)
175 assert.Contains(t, resp.Body, `"num_doc_writes":1`)
176
177 // Create db1 again and expect it to fail
178 resp = BootstrapAdminRequest(t, sc, http.MethodPut, "/db1/", dbConfig)
179 resp.RequireStatus(http.StatusPreconditionFailed)
180 assert.Contains(t, resp.Body, fmt.Sprintf(`Duplicate database name \"%s\"`, "db1"))
181
182 // check to see we still have a doc written stat (as a proxy to determine if the database restarted)
183 resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/_expvar", "")
184 resp.RequireStatus(http.StatusOK)
185 assert.Contains(t, resp.Body, `"num_doc_writes":1`)
186}
187
188// TestBootstrapDiagnosticAPI asserts on diagnostic API endpoints
189func TestBootstrapPingAPI(t *testing.T) {

Callers

nothing calls this directly

Calls 11

SetUpTestLoggingFunction · 0.92
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
TestUseXattrsFunction · 0.92
TestsDisableGSIFunction · 0.92
StartBootstrapServerFunction · 0.85
BootstrapAdminRequestFunction · 0.85
RequireStatusMethod · 0.80
CloseMethod · 0.65
GetNameMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected