up
Some checks failed
Some checks failed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# AirGap Tests
|
||||
|
||||
## Notes
|
||||
- Mongo-backed tests use Mongo2Go and require the OpenSSL 1.1 shim. The shim is auto-initialized via `OpenSslAutoInit` from `tests/shared`.
|
||||
- If Mongo2Go fails to start (missing `libssl.so.1.1` / `libcrypto.so.1.1`), ensure `tests/shared/native/linux-x64` is on `LD_LIBRARY_PATH` (handled by the shim) or install OpenSSL 1.1 compatibility libs locally.
|
||||
- Tests default to in-memory stores unless `AirGap:Mongo:ConnectionString` is provided.
|
||||
- Tests now run entirely against in-memory stores (no MongoDB or external services required).
|
||||
- Keep fixtures deterministic: stable ordering, UTC timestamps, fixed seeds where applicable.
|
||||
- Sealed-mode and staleness tests rely on local fixture bundles only; no network access is needed.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user