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

Function TestAllowConflictsConfig

rest/api_test.go:3488–3542  ·  view source on GitHub ↗

TestAllowConflictsConfig verifies that the database configuration does not allow the `allow_conflicts` property to be set to true. `allow_conflicts` is no longer supported in SGW 4.0. This test ensures that a config loaded will add the database to invalid configs. The config will be fixed when a dat

(t *testing.T)

Source from the content-addressed store, hash-verified

3486// database to invalid configs. The config will be fixed when a database is created
3487// without `allow_conflicts`
3488func TestAllowConflictsConfig(t *testing.T) {
3489
3490 ctx := t.Context()
3491
3492 rt := NewRestTester(t, &RestTesterConfig{
3493 PersistentConfig: true,
3494 })
3495 defer rt.Close()
3496
3497 const (
3498 dbName = "db1"
3499 errResp = "allow_conflicts cannot be set to true"
3500 allDBsURL = "/_all_dbs?verbose=true"
3501 )
3502
3503 dbConfig := rt.NewDbConfig()
3504 dbConfig.AllowConflicts = base.Ptr(true)
3505
3506 resp := rt.CreateDatabase(dbName, dbConfig)
3507
3508 RequireStatus(t, resp, http.StatusBadRequest)
3509 assert.Contains(t, resp.Body.String(), errResp)
3510
3511 dbConfig = rt.NewDbConfig()
3512 dbConfig.Name = dbName
3513
3514 rt.CreateDatabase(dbName, dbConfig)
3515
3516 // Send an admin request to retrieve all databases and verify the response.
3517 resp = rt.SendAdminRequest(http.MethodGet, allDBsURL, "")
3518 RequireStatus(t, resp, http.StatusOK)
3519 require.Equal(t, fmt.Sprintf(`[{"db_name":"%s","bucket":"%s","state":"Online"}]`, rt.GetDatabase().Name, rt.GetDatabase().Bucket.GetName()), resp.Body.String())
3520 bucketName := rt.GetDatabase().Bucket.GetName()
3521
3522 // Set the `AllowConflicts` property to true in the persisted database configuration and try to load it (this covers cases where the config value was previously set from an older SGW version that allowed this configuration).
3523 rt.updatePersistedConfig(dbName, func(config *DatabaseConfig) {
3524 config.DbConfig.AllowConflicts = base.Ptr(true)
3525 })
3526
3527 // Reload the database configuration and verify that an error is returned.
3528 _, err := rt.RestTesterServerContext.ReloadDatabase(ctx, dbName, false)
3529 require.Error(t, err)
3530
3531 // Verify that the database is now in an offline state with the appropriate error message.
3532 resp = rt.SendAdminRequest(http.MethodGet, allDBsURL, "")
3533 RequireStatus(t, resp, http.StatusOK)
3534 require.Equal(t, fmt.Sprintf(`[{"db_name":"%s","bucket":"%s","state":"Offline","database_error":{"error_message":"Allow conflicts is set to true","error_code":9}}]`, dbName, bucketName), resp.Body.String())
3535
3536 // Recreate the database with the original configuration and verify it is online.
3537 rt.CreateDatabase(dbName, dbConfig)
3538 rt.WaitForDBOnline()
3539 resp = rt.SendAdminRequest(http.MethodGet, allDBsURL, "")
3540 RequireStatus(t, resp, http.StatusOK)
3541 require.Equal(t, fmt.Sprintf(`[{"db_name":"%s","bucket":"%s","state":"Online"}]`, rt.GetDatabase().Name, rt.GetDatabase().Bucket.GetName()), resp.Body.String())
3542}
3543
3544// TestDisableAllowStarChannel verifies that the database configuration does not allow
3545// a database to be loaded with the `enable_star_channel` property to be set to false.

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDbConfigMethod · 0.95
CreateDatabaseMethod · 0.95
SendAdminRequestMethod · 0.95
GetDatabaseMethod · 0.95
updatePersistedConfigMethod · 0.95
WaitForDBOnlineMethod · 0.95
PtrFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
ReloadDatabaseMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected