up
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled

This commit is contained in:
StellaOps Bot
2025-12-11 08:20:15 +02:00
parent b8b493913a
commit ce1f282ce0
65 changed files with 5481 additions and 1803 deletions

View File

@@ -1,26 +1,13 @@
using MongoDB.Bson;
using MongoDB.Driver;
using StellaOps.AirGap.Controller.Domain;
using StellaOps.AirGap.Controller.Stores;
using StellaOps.AirGap.Time.Models;
using StellaOps.Testing;
using Xunit;
namespace StellaOps.AirGap.Controller.Tests;
public class MongoAirGapStateStoreTests : IDisposable
public class InMemoryAirGapStateStoreTests
{
private readonly MongoRunnerFixture _mongo = new();
private readonly IMongoCollection<AirGapStateDocument> _collection;
private readonly MongoAirGapStateStore _store;
public MongoAirGapStateStoreTests()
{
OpenSslAutoInit.Init();
var database = _mongo.Client.GetDatabase("airgap_tests");
_collection = MongoAirGapStateStore.EnsureCollection(database);
_store = new MongoAirGapStateStore(_collection);
}
private readonly InMemoryAirGapStateStore _store = new();
[Fact]
public async Task Upsert_and_read_state_by_tenant()
@@ -67,22 +54,6 @@ public class MongoAirGapStateStoreTests : IDisposable
Assert.Equal("absent", stored.TenantId);
}
[Fact]
public async Task Creates_unique_index_on_tenant_and_id()
{
var indexes = await _collection.Indexes.List().ToListAsync();
var match = indexes.FirstOrDefault(idx =>
{
var key = idx["key"].AsBsonDocument;
return key.ElementCount == 2
&& key.Names.ElementAt(0) == "tenant_id"
&& key.Names.ElementAt(1) == "_id";
});
Assert.NotNull(match);
Assert.True(match!["unique"].AsBoolean);
}
[Fact]
public async Task Parallel_upserts_keep_single_document()
{
@@ -101,9 +72,6 @@ public class MongoAirGapStateStoreTests : IDisposable
var stored = await _store.GetAsync("tenant-parallel");
Assert.StartsWith("hash-", stored.PolicyHash);
var count = await _collection.CountDocumentsAsync(Builders<AirGapStateDocument>.Filter.Eq(x => x.TenantId, "tenant-parallel"));
Assert.Equal(1, count);
}
[Fact]
@@ -125,9 +93,6 @@ public class MongoAirGapStateStoreTests : IDisposable
var stored = await _store.GetAsync(t);
Assert.Equal($"hash-{t}", stored.PolicyHash);
}
var totalDocs = await _collection.CountDocumentsAsync(FilterDefinition<AirGapStateDocument>.Empty);
Assert.Equal(tenants.Length, totalDocs);
}
[Fact]
@@ -175,9 +140,4 @@ public class MongoAirGapStateStoreTests : IDisposable
Assert.Equal($"ph-{t}", state.PolicyHash);
}
}
public void Dispose()
{
_mongo.Dispose();
}
}

View File

@@ -1,24 +0,0 @@
using Mongo2Go;
using MongoDB.Driver;
using StellaOps.Testing;
namespace StellaOps.AirGap.Controller.Tests;
internal sealed class MongoRunnerFixture : IDisposable
{
private readonly MongoDbRunner _runner;
public MongoRunnerFixture()
{
OpenSslAutoInit.Init();
_runner = MongoDbRunner.Start(singleNodeReplSet: true);
Client = new MongoClient(_runner.ConnectionString);
}
public IMongoClient Client { get; }
public void Dispose()
{
_runner.Dispose();
}
}

View File

@@ -9,7 +9,6 @@
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Mongo2Go" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../../src/AirGap/StellaOps.AirGap.Controller/StellaOps.AirGap.Controller.csproj" />