2022-01-26 14:19:04 +00:00
|
|
|
using System.Linq;
|
2021-02-28 11:40:40 +00:00
|
|
|
using INetMock.Client.PCAP;
|
|
|
|
using INetMock.Client.PCAP.Client;
|
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
namespace INetMock.Client.IntegrationTest.PCAP.Client;
|
|
|
|
|
|
|
|
public class PcapApiClientTests : IClassFixture<INetMockFixture>
|
2021-02-28 11:40:40 +00:00
|
|
|
{
|
2022-01-26 14:19:04 +00:00
|
|
|
private readonly IPcapApiClient _apiClient;
|
2023-09-15 17:01:48 +00:00
|
|
|
private readonly ITestOutputHelper _outputHelper;
|
2022-01-26 14:19:04 +00:00
|
|
|
|
|
|
|
public PcapApiClientTests(ITestOutputHelper testOutputHelper, INetMockFixture inetMockFixture)
|
2021-02-28 11:40:40 +00:00
|
|
|
{
|
2022-01-26 14:19:04 +00:00
|
|
|
_outputHelper = testOutputHelper;
|
|
|
|
_apiClient = new PcapApiClient(inetMockFixture.INetMockSocketPath);
|
|
|
|
}
|
2021-02-28 11:40:40 +00:00
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
[Fact]
|
|
|
|
public async void ListAvailableDevicesAsync_RunningContainer_AtLeastLoopbackDevice()
|
|
|
|
{
|
|
|
|
var devs = await _apiClient.ListAvailableDevicesAsync();
|
2021-02-28 11:40:40 +00:00
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
foreach (var (name, _) in devs)
|
2021-02-28 11:40:40 +00:00
|
|
|
{
|
2022-01-26 14:19:04 +00:00
|
|
|
_outputHelper.WriteLine(name);
|
2021-02-28 11:40:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
Assert.Contains(devs, device => device.Name.Equals("lo"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async void ListActiveRecordingsAsync_NoRecordingsRunning_EmptyResult()
|
|
|
|
{
|
|
|
|
var recordings = await _apiClient.ListActiveRecordingsAsync();
|
|
|
|
|
|
|
|
Assert.Empty(recordings);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async void StartPcapFileRecordingAsync_RecordLoopbackInterface_RunningRecording()
|
|
|
|
{
|
|
|
|
var recordingDevice = (await _apiClient.ListAvailableDevicesAsync()).FirstOrDefault();
|
|
|
|
if (recordingDevice == null)
|
2021-02-28 11:40:40 +00:00
|
|
|
{
|
2022-01-26 14:19:04 +00:00
|
|
|
return;
|
2021-02-28 11:40:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
var targetPath = $"/tmp/{recordingDevice.Name}_record.pcap";
|
2023-09-15 17:01:48 +00:00
|
|
|
await _apiClient.StartPcapFileRecordingAsync(new RecordingRequest(recordingDevice.Name, targetPath));
|
2021-02-28 11:40:40 +00:00
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
var subscriptions = await _apiClient.ListActiveRecordingsAsync();
|
|
|
|
Assert.Contains(subscriptions, subscription =>
|
|
|
|
subscription.Device.Equals(recordingDevice.Name) &&
|
|
|
|
subscription.ConsumerName.Equals(targetPath)
|
|
|
|
);
|
|
|
|
foreach (var subscription in subscriptions)
|
|
|
|
{
|
|
|
|
await _apiClient.StopPcapFileRecordingAsync(subscription.ConsumerKey);
|
2021-02-28 11:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|