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

Function TestPersistentConfigNoBucketField

rest/persistent_config_test.go:1373–1470  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1371}
1372
1373func TestPersistentConfigNoBucketField(t *testing.T) {
1374 base.RequireNumTestBuckets(t, 2)
1375
1376 base.SetUpTestLogging(t, base.LevelTrace, base.KeyConfig)
1377
1378 b1 := base.GetTestBucket(t)
1379 defer b1.Close(base.TestCtx(t))
1380 b1Name := b1.GetName()
1381
1382 // at the end of the test we'll move config from b1 into b2 to test backup/restore-type migration
1383 b2 := base.GetTestBucket(t)
1384 defer b2.Close(base.TestCtx(t))
1385 b2Name := b2.GetName()
1386
1387 rt := NewRestTester(t, &RestTesterConfig{
1388 PersistentConfig: true,
1389 CustomTestBucket: b1.NoCloseClone(),
1390 })
1391 defer rt.Close()
1392
1393 dbName := b1Name
1394
1395 dbConfig := rt.NewDbConfig()
1396 // will infer from db name in handler and stamp into config (as of CBG-3353)
1397 dbConfig.Bucket = nil
1398 resp := rt.CreateDatabase(dbName, dbConfig)
1399 RequireStatus(t, resp, http.StatusCreated)
1400
1401 // read back config in bucket to see if bucket field was stamped into the config
1402 var databaseConfig DatabaseConfig
1403 groupID := rt.ServerContext().Config.Bootstrap.ConfigGroupID
1404 configDocID := PersistentConfigKey(base.TestCtx(t), groupID, b1Name)
1405 _, err := rt.GetDatabase().MetadataStore.Get(configDocID, &databaseConfig)
1406 require.NoError(t, err)
1407 require.NotNil(t, databaseConfig.Bucket)
1408 assert.Equal(t, b1Name, *databaseConfig.Bucket, "bucket field should be stamped into config")
1409
1410 // manually strip out bucket to test backwards compatibility (older configs don't always have this field set)
1411 _, err = rt.GetDatabase().MetadataStore.Update(configDocID, 0, func(current []byte) (updated []byte, expiry *uint32, delete bool, err error) {
1412 var d DatabaseConfig
1413 require.NoError(t, base.JSONUnmarshal(current, &d))
1414 d.Bucket = nil
1415 newConfig, err := base.JSONMarshal(d)
1416 return newConfig, nil, false, err
1417 })
1418 require.NoError(t, err)
1419
1420 count, err := rt.ServerContext().fetchAndLoadConfigs(base.TestCtx(t), false)
1421 require.NoError(t, err)
1422 require.Equal(t, 1, count, "should have loaded 1 config")
1423
1424 _, err = rt.UpdatePersistedBucketName(&databaseConfig, &b2Name)
1425 require.NoError(t, err)
1426
1427 dbBucketMismatch := base.SyncGatewayStats.GlobalStats.ConfigStat.DatabaseBucketMismatches.Value()
1428
1429 // expect config to fail to load due to bucket mismatch
1430 count, err = rt.ServerContext().fetchAndLoadConfigs(base.TestCtx(t), false)

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDbConfigMethod · 0.95
CreateDatabaseMethod · 0.95
ServerContextMethod · 0.95
GetDatabaseMethod · 0.95
UpsertDbConfigMethod · 0.95
RequireNumTestBucketsFunction · 0.92
SetUpTestLoggingFunction · 0.92
GetTestBucketFunction · 0.92
TestCtxFunction · 0.92
JSONUnmarshalFunction · 0.92

Tested by

no test coverage detected