TestBootstrapDuplicateDatabase will attempt to create a second database and ensure this isn't allowed.
(t *testing.T)
| 147 | |
| 148 | // TestBootstrapDuplicateDatabase will attempt to create a second database and ensure this isn't allowed. |
| 149 | func 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 |
| 189 | func TestBootstrapPingAPI(t *testing.T) { |
nothing calls this directly
no test coverage detected