Skip to content

Commit

Permalink
Cleaning up the ZAP image too after completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Nov 30, 2023
1 parent 1e2993d commit 116bd83
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Lombiq.Tests.UI/SecurityScanning/ZapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,31 @@ public async Task<SecurityScanResult> RunSecurityScanAsync(
return new SecurityScanResult(reportsDirectoryPath, SarifLog.Load(jsonReports[0]));
}

public ValueTask DisposeAsync()
public async ValueTask DisposeAsync()
{
if (_cancellationTokenSource != null && !_cancellationTokenSource.IsCancellationRequested)
{
_cancellationTokenSource.Cancel();
_cancellationTokenSource.Dispose();
}

return ValueTask.CompletedTask;
try
{
using var cleanupCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
var cleanupCancellationToken = cleanupCancellationTokenSource.Token;
var imagesOutput = await _docker.ExecuteAndGetOutputAsync(
cleanupCancellationToken, "images", _zapImage, "--format", "{{.ID}}");

if (!string.IsNullOrEmpty(imagesOutput))
{
await _docker.ExecuteAsync(cleanupCancellationToken, "image", "rm", _zapImage);
}
}
catch (Exception ex)
{
_testOutputHelper.WriteLineTimestampedAndDebug(
"Removing the Docker image {0} for ZAP failed with the following exception: {1}", _zapImage, ex);
}
}

private async Task EnsureInitializedAsync()
Expand Down

0 comments on commit 116bd83

Please sign in to comment.