Files
git.stella-ops.org/tests/offline/StellaOps.Offline.E2E.Tests/NetworkIsolationTests.cs

65 lines
1.9 KiB
C#

namespace StellaOps.Offline.E2E.Tests;
using StellaOps.Testing.AirGap;
[Trait("Category", "Unit")]
[Trait("Category", "NetworkIsolation")]
public class NetworkIsolationTests : NetworkIsolatedTestBase
{
[Fact]
public void NetworkMonitor_DetectsSocketExceptions()
{
// This test verifies the monitoring infrastructure itself
var attempts = new List<NetworkAttempt>();
var monitor = new NetworkMonitor(attempts.Add);
monitor.StartMonitoringAsync().Wait();
// Simulate network attempt (this won't actually make a network call in test)
// In real scenario, any socket exception would be caught
monitor.StopMonitoringAsync().Wait();
// In this test, we're just verifying the infrastructure is set up
// Real network attempts would be caught in integration tests
}
[Fact]
public void GetOfflineBundlePath_ReturnsConfiguredPath()
{
var bundlePath = GetOfflineBundlePath();
bundlePath.Should().NotBeNullOrEmpty();
// Either from environment variable or default
(bundlePath.Contains("fixtures") || bundlePath.Contains("offline-bundle"))
.Should().BeTrue();
}
[Fact]
public void AssertNoNetworkCalls_PassesWhenNoAttempts()
{
// Should not throw
AssertNoNetworkCalls();
}
[Fact]
public async Task NetworkIsolatedTest_CanAccessLocalFiles()
{
// Verify we can still access local filesystem
var tempFile = Path.GetTempFileName();
try
{
await File.WriteAllTextAsync(tempFile, "test content");
var content = await File.ReadAllTextAsync(tempFile);
content.Should().Be("test content");
AssertNoNetworkCalls();
}
finally
{
if (File.Exists(tempFile))
File.Delete(tempFile);
}
}
}