TestNotFoundOnInvalidDatabase: - Create rest tester with large config polling interval - Insert a bad dbConfig into the bucket - Manually fetch and load db from buckets - Assert that the bad config is tracked as invalid config - Delete the bad config manually and attempt to correct the db config thr
(t *testing.T)
| 3005 | // - Delete the bad config manually and attempt to correct the db config through create db endpoint |
| 3006 | // - Assert db is removed form invalid db's and is now a running database on server context |
| 3007 | func TestNotFoundOnInvalidDatabase(t *testing.T) { |
| 3008 | rt := NewRestTester(t, &RestTesterConfig{ |
| 3009 | CustomTestBucket: base.GetTestBucket(t), |
| 3010 | PersistentConfig: true, |
| 3011 | MutateStartupConfig: func(config *StartupConfig) { |
| 3012 | // configure the interval time to not run |
| 3013 | config.Bootstrap.ConfigUpdateFrequency = base.NewConfigDuration(100 * time.Second) |
| 3014 | }, |
| 3015 | DatabaseConfig: nil, |
| 3016 | }) |
| 3017 | defer rt.Close() |
| 3018 | realBucketName := rt.CustomTestBucket.GetName() |
| 3019 | |
| 3020 | // create a new invalid db config and persist to bucket |
| 3021 | badName := "badBucketName" |
| 3022 | dbConfig := rt.NewDbConfig() |
| 3023 | dbConfig.Name = "db1" |
| 3024 | |
| 3025 | version, err := GenerateDatabaseConfigVersionID(rt.Context(), "", &dbConfig) |
| 3026 | require.NoError(t, err) |
| 3027 | metadataID, metadataIDError := rt.ServerContext().BootstrapContext.ComputeMetadataIDForDbConfig(base.TestCtx(t), &dbConfig) |
| 3028 | require.NoError(t, metadataIDError) |
| 3029 | |
| 3030 | // insert the db config with bad bucket name |
| 3031 | dbConfig.Bucket = &badName |
| 3032 | persistedConfig := DatabaseConfig{ |
| 3033 | Version: version, |
| 3034 | MetadataID: metadataID, |
| 3035 | DbConfig: dbConfig, |
| 3036 | SGVersion: base.ProductVersion.String(), |
| 3037 | } |
| 3038 | rt.InsertDbConfigToBucket(&persistedConfig, rt.CustomTestBucket.GetName()) |
| 3039 | |
| 3040 | // manually fetch and load db configs from bucket |
| 3041 | _, err = rt.ServerContext().fetchAndLoadConfigs(rt.Context(), false) |
| 3042 | require.NoError(t, err) |
| 3043 | |
| 3044 | // assert the config is picked as invalid db config |
| 3045 | require.EventuallyWithT(t, func(c *assert.CollectT) { |
| 3046 | invalidDatabases := rt.ServerContext().AllInvalidDatabaseNames(t) |
| 3047 | assert.Equal(c, 1, len(invalidDatabases)) |
| 3048 | }, time.Second*10, time.Millisecond*100) |
| 3049 | |
| 3050 | resp := rt.SendAdminRequest(http.MethodGet, "/db1/", "") |
| 3051 | RequireStatus(t, resp, http.StatusNotFound) |
| 3052 | assert.Contains(t, resp.Body.String(), "You must update database config immediately") |
| 3053 | |
| 3054 | // delete the invalid db config to force the not found error |
| 3055 | rt.RemoveDbConfigFromBucket(dbConfig.Name, realBucketName) |
| 3056 | |
| 3057 | // fix the bucket name and try fix corrupt db through create db endpoint |
| 3058 | dbConfig.Bucket = &realBucketName |
| 3059 | RequireStatus(t, rt.CreateDatabase(dbConfig.Name, dbConfig), http.StatusCreated) |
| 3060 | |
| 3061 | // assert the config is remove the invalid config and we have a running db |
| 3062 | require.EventuallyWithT(t, func(c *assert.CollectT) { |
| 3063 | invalidDatabases := rt.ServerContext().AllInvalidDatabaseNames(t) |
| 3064 | assert.Equal(c, 0, len(invalidDatabases)) |
nothing calls this directly
no test coverage detected