(t *testing.T)
| 1116 | } |
| 1117 | |
| 1118 | func TestMigratev30PersistentConfig(t *testing.T) { |
| 1119 | base.TestRequiresCollections(t) |
| 1120 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP, base.KeyConfig) |
| 1121 | |
| 1122 | for _, test := range persistentConfigTestCases() { |
| 1123 | t.Run(test.name, func(t *testing.T) { |
| 1124 | sc, closeFn := startBootstrapServerWithoutConfigPolling(t, test.xattrConfig) |
| 1125 | defer closeFn() |
| 1126 | |
| 1127 | ctx := base.TestCtx(t) |
| 1128 | tb := base.GetTestBucket(t) |
| 1129 | defer tb.Close(ctx) |
| 1130 | |
| 1131 | bucketName := tb.GetName() |
| 1132 | groupID := sc.Config.Bootstrap.ConfigGroupID |
| 1133 | defaultDbName := "defaultDb" |
| 1134 | defaultVersion := "1-abc" |
| 1135 | defaultDbConfig := makeDbConfig(tb.GetName(), defaultDbName, nil) |
| 1136 | defaultDatabaseConfig := &DatabaseConfig{ |
| 1137 | DbConfig: defaultDbConfig, |
| 1138 | Version: defaultVersion, |
| 1139 | } |
| 1140 | |
| 1141 | _, insertError := sc.BootstrapContext.Connection.InsertMetadataDocument(ctx, bucketName, PersistentConfigKey30(ctx, groupID), defaultDatabaseConfig) |
| 1142 | require.NoError(t, insertError) |
| 1143 | |
| 1144 | migrateErr := sc.migrateV30Configs(ctx) |
| 1145 | require.NoError(t, migrateErr) |
| 1146 | |
| 1147 | // Fetch the registry, verify database has been migrated |
| 1148 | registry, registryErr := sc.BootstrapContext.getGatewayRegistry(ctx, bucketName) |
| 1149 | require.NoError(t, registryErr) |
| 1150 | require.NotNil(t, registry) |
| 1151 | migratedDb, found := registry.getRegistryDatabase(groupID, defaultDbName) |
| 1152 | require.True(t, found) |
| 1153 | require.Equal(t, "1-abc", migratedDb.Version) |
| 1154 | // Verify legacy config has been removed |
| 1155 | _, getError := sc.BootstrapContext.Connection.GetMetadataDocument(ctx, bucketName, PersistentConfigKey30(ctx, groupID), defaultDatabaseConfig) |
| 1156 | base.RequireDocNotFoundError(t, getError) |
| 1157 | |
| 1158 | // Update the db in the registry, and recreate legacy config. Verify migration doesn't overwrite |
| 1159 | _, insertError = sc.BootstrapContext.Connection.InsertMetadataDocument(ctx, bucketName, PersistentConfigKey30(ctx, groupID), defaultDatabaseConfig) |
| 1160 | require.NoError(t, insertError) |
| 1161 | _, updateError := sc.BootstrapContext.UpdateConfig(ctx, bucketName, groupID, defaultDbName, func(bucketDbConfig *DatabaseConfig) (updatedConfig *DatabaseConfig, err error) { |
| 1162 | bucketDbConfig.Version = "2-abc" |
| 1163 | return bucketDbConfig, nil |
| 1164 | }) |
| 1165 | require.NoError(t, updateError) |
| 1166 | migrateErr = sc.migrateV30Configs(ctx) |
| 1167 | require.NoError(t, migrateErr) |
| 1168 | registry, registryErr = sc.BootstrapContext.getGatewayRegistry(ctx, bucketName) |
| 1169 | require.NoError(t, registryErr) |
| 1170 | require.NotNil(t, registry) |
| 1171 | migratedDb, found = registry.getRegistryDatabase(groupID, defaultDbName) |
| 1172 | require.True(t, found) |
| 1173 | require.Equal(t, "2-abc", migratedDb.Version) |
| 1174 | |
| 1175 | // Verify legacy config has been removed |
nothing calls this directly
no test coverage detected