Add unit tests and implementations for MongoDB index models and OpenAPI metadata
- Implemented `MongoIndexModelTests` to verify index models for various stores. - Created `OpenApiMetadataFactory` with methods to generate OpenAPI metadata. - Added tests for `OpenApiMetadataFactory` to ensure expected defaults and URL overrides. - Introduced `ObserverSurfaceSecrets` and `WebhookSurfaceSecrets` for managing secrets. - Developed `RuntimeSurfaceFsClient` and `WebhookSurfaceFsClient` for manifest retrieval. - Added dependency injection tests for `SurfaceEnvironmentRegistration` in both Observer and Webhook contexts. - Implemented tests for secret resolution in `ObserverSurfaceSecretsTests` and `WebhookSurfaceSecretsTests`. - Created `EnsureLinkNotMergeCollectionsMigrationTests` to validate MongoDB migration logic. - Added project files for MongoDB tests and NuGet package mirroring.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
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 EnsureLinkNotMergeCollectionsMigrationTests : 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("lnm-migration-tests");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task DisposeAsync()
|
||||
{
|
||||
_runner.Dispose();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreatesCollectionsAndIndexesIdempotently()
|
||||
{
|
||||
var migration = new EnsureLinkNotMergeCollectionsMigration();
|
||||
|
||||
await migration.ApplyAsync(_database, CancellationToken.None);
|
||||
await migration.ApplyAsync(_database, CancellationToken.None); // idempotent second run
|
||||
|
||||
var collections = await _database.ListCollectionNames().ToListAsync();
|
||||
collections.Should().Contain(new[]
|
||||
{
|
||||
MongoStorageDefaults.Collections.AdvisoryObservations,
|
||||
MongoStorageDefaults.Collections.AdvisoryLinksets
|
||||
});
|
||||
|
||||
var linksetIndexes = await _database
|
||||
.GetCollection<BsonDocument>(MongoStorageDefaults.Collections.AdvisoryLinksets)
|
||||
.Indexes.List()
|
||||
.ToListAsync();
|
||||
|
||||
linksetIndexes.Should().ContainSingle(i => i["name"] == "linkset_tenant_advisory_source" && i["unique"].AsBoolean);
|
||||
|
||||
var obsIndexes = await _database
|
||||
.GetCollection<BsonDocument>(MongoStorageDefaults.Collections.AdvisoryObservations)
|
||||
.Indexes.List()
|
||||
.ToListAsync();
|
||||
|
||||
obsIndexes.Should().Contain(i => i["name"] == "obs_prov_sourceArtifactSha_unique" && i["unique"].AsBoolean);
|
||||
|
||||
var linksetValidator = await GetValidatorAsync(MongoStorageDefaults.Collections.AdvisoryLinksets);
|
||||
linksetValidator.Should().NotBeNull();
|
||||
}
|
||||
|
||||
private async Task<BsonDocument?> GetValidatorAsync(string collection)
|
||||
{
|
||||
var filter = new BsonDocument("name", collection);
|
||||
var cursor = await _database.ListCollectionsAsync(new ListCollectionsOptions { Filter = filter });
|
||||
var doc = await cursor.FirstOrDefaultAsync();
|
||||
return doc?"options"?"validator"?.AsBsonDocument;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
||||
<PackageReference Include="Mongo2Go" Version="4.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../../src/Concelier/__Libraries/StellaOps.Concelier.Storage.Mongo/StellaOps.Concelier.Storage.Mongo.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user