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

Function TestCorruptDbConfigHandling

rest/adminapitest/admin_api_test.go:951–1025  ·  view source on GitHub ↗

TestCorruptDbConfigHandling: - Create persistent config rest tester - Create a db with a non-corrupt config - Grab the persisted config from the bucket for purposes of changing the bucket name on it (this simulates a dbconfig becoming corrupt) - Update the persisted config to change the bucket name

(t *testing.T)

Source from the content-addressed store, hash-verified

949// - assert the db returns to the server context and is removed from corrupt database tracking AND that the bucket name
950// on the config now matches the rest tester bucket name
951func TestCorruptDbConfigHandling(t *testing.T) {
952 base.LongRunningTest(t)
953 base.SetUpTestLogging(t, base.LevelInfo, base.KeyConfig)
954
955 rt := rest.NewRestTester(t, &rest.RestTesterConfig{
956 CustomTestBucket: base.GetTestBucket(t),
957 PersistentConfig: true,
958 MutateStartupConfig: func(config *rest.StartupConfig) {
959 // configure the interval time to large interval, so it doesn't run during test
960 config.Bootstrap.ConfigUpdateFrequency = base.NewConfigDuration(10 * time.Minute)
961 },
962 })
963 defer rt.Close()
964 ctx := base.TestCtx(t)
965
966 // create db with correct config
967 dbConfig := rt.NewDbConfig()
968 resp := rt.CreateDatabase("db1", dbConfig)
969 rest.RequireStatus(t, resp, http.StatusCreated)
970
971 // grab the persisted db config from the bucket
972 databaseConfig := rest.DatabaseConfig{}
973 _, err := rt.ServerContext().BootstrapContext.GetConfig(rt.Context(), rt.CustomTestBucket.GetName(), rt.ServerContext().Config.Bootstrap.ConfigGroupID, "db1", &databaseConfig)
974 require.NoError(t, err)
975
976 // update the persisted config to a fake bucket name
977 newBucketName := "fakeBucket"
978 _, err = rt.UpdatePersistedBucketName(&databaseConfig, &newBucketName)
979 require.NoError(t, err)
980
981 // force reload of configs from bucket
982 rt.ServerContext().ForceDbConfigsReload(t, ctx)
983
984 // assert that the in memory representation of the db config on the server context is gone now we have broken the config
985 responseConfig := rt.ServerContext().GetDbConfig("db1")
986 assert.Nil(t, responseConfig)
987
988 require.Len(t, rt.ServerContext().AllInvalidDatabaseNames(t), 1)
989
990 // assert that fetching config fails with the correct error message to the user
991 resp = rt.SendAdminRequest(http.MethodGet, "/db1/_config", "")
992 rest.RequireStatus(t, resp, http.StatusNotFound)
993 assert.Contains(t, resp.Body.String(), "You must update database config immediately")
994
995 // assert trying to delete fails with the correct error message to the user
996 resp = rt.SendAdminRequest(http.MethodDelete, "/db1/", "")
997 rest.RequireStatus(t, resp, http.StatusNotFound)
998 assert.Contains(t, resp.Body.String(), "You must update database config immediately")
999
1000 // correct the name through update to config
1001 resp = rt.ReplaceDbConfig("db1", dbConfig)
1002 rest.RequireStatus(t, resp, http.StatusNotFound)
1003 assert.Contains(t, resp.Body.String(), "You must update database config immediately")
1004
1005 // create db of same name with correct db config to correct the corrupt db config
1006 resp = rt.CreateDatabase("db1", dbConfig)
1007 rest.RequireStatus(t, resp, http.StatusCreated)
1008

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDbConfigMethod · 0.95
CreateDatabaseMethod · 0.95
ServerContextMethod · 0.95
ContextMethod · 0.95
SendAdminRequestMethod · 0.95
ReplaceDbConfigMethod · 0.95
LongRunningTestFunction · 0.92
SetUpTestLoggingFunction · 0.92
NewRestTesterFunction · 0.92

Tested by

no test coverage detected