Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Added NullAdvisoryObservationEventTransport for handling advisory observation events. - Created IOrchestratorRegistryStore interface for orchestrator registry operations. - Implemented MongoOrchestratorRegistryStore for MongoDB interactions with orchestrator data. - Defined OrchestratorCommandDocument and OrchestratorCommandRecord for command handling. - Added OrchestratorHeartbeatDocument and OrchestratorHeartbeatRecord for heartbeat tracking. - Created OrchestratorRegistryDocument and OrchestratorRegistryRecord for registry management. - Developed tests for orchestrator collections migration and MongoOrchestratorRegistryStore functionality. - Introduced AirgapImportRequest and AirgapImportValidator for air-gapped VEX bundle imports. - Added incident mode rules sample JSON for notifier configuration.
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using FluentAssertions;
|
|
using Mongo2Go;
|
|
using MongoDB.Bson;
|
|
using MongoDB.Driver;
|
|
using StellaOps.Concelier.Storage.Mongo.Migrations;
|
|
|
|
namespace StellaOps.Concelier.Storage.Mongo.Tests;
|
|
|
|
public sealed class EnsureOrchestratorCollectionsMigrationTests : IAsyncLifetime
|
|
{
|
|
private MongoDbRunner _runner = null!;
|
|
private IMongoDatabase _database = null!;
|
|
|
|
public Task InitializeAsync()
|
|
{
|
|
_runner = MongoDbRunner.Start(singleNodeReplSet: true);
|
|
var client = new MongoClient(_runner.ConnectionString);
|
|
_database = client.GetDatabase("orch-migration-tests");
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task DisposeAsync()
|
|
{
|
|
_runner.Dispose();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreatesOrchestratorCollectionsAndIndexes()
|
|
{
|
|
var migration = new EnsureOrchestratorCollectionsMigration();
|
|
|
|
await migration.ApplyAsync(_database, CancellationToken.None);
|
|
|
|
var collections = await _database.ListCollectionNames().ToListAsync();
|
|
collections.Should().Contain(
|
|
new[]
|
|
{
|
|
MongoStorageDefaults.Collections.OrchestratorRegistry,
|
|
MongoStorageDefaults.Collections.OrchestratorCommands,
|
|
MongoStorageDefaults.Collections.OrchestratorHeartbeats,
|
|
});
|
|
|
|
var registryIndexes = await GetIndexNamesAsync(MongoStorageDefaults.Collections.OrchestratorRegistry);
|
|
registryIndexes.Should().Contain("orch_registry_tenant_connector");
|
|
|
|
var commandIndexes = await GetIndexNamesAsync(MongoStorageDefaults.Collections.OrchestratorCommands);
|
|
commandIndexes.Should().Contain("orch_cmd_tenant_connector_run_seq");
|
|
commandIndexes.Should().Contain("orch_cmd_expiresAt_ttl");
|
|
|
|
var heartbeatIndexes = await GetIndexNamesAsync(MongoStorageDefaults.Collections.OrchestratorHeartbeats);
|
|
heartbeatIndexes.Should().Contain("orch_hb_tenant_connector_run_seq");
|
|
}
|
|
|
|
private async Task<IReadOnlyCollection<string>> GetIndexNamesAsync(string collection)
|
|
{
|
|
var docs = await _database.GetCollection<BsonDocument>(collection)
|
|
.Indexes
|
|
.List()
|
|
.ToListAsync();
|
|
|
|
return docs.Select(d => d["name"].AsString).ToArray();
|
|
}
|
|
}
|