Skip to content

Commit 755348d

Browse files
committed
Test blob-missing skips record creation
1 parent f5977fd commit 755348d

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

api.Tests/Integration/EndToEndPipelineTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ await _context
122122
Assert.Equal(AnalysisRunStatus.Succeeded, workflow.AnalysisRun.Status);
123123
}
124124

125+
[Fact]
126+
public async Task BlobDoesNotExist_NoInspectionRecordOrWorkflowCreated_AndNoAnalysisTriggered()
127+
{
128+
_factory.BlobStorageService.BlobExists = false;
129+
var message = _db.NewIsarInspectionResultMessage(requiredAnalysis: ["per-record-test"]);
130+
131+
await ProcessInspectionResultInScope(message);
132+
133+
Assert.False(
134+
await _context.InspectionRecords.AnyAsync(TestContext.Current.CancellationToken),
135+
"No inspection record should be created when the ISAR blob does not exist."
136+
);
137+
Assert.False(
138+
await _context.Workflows.AnyAsync(TestContext.Current.CancellationToken),
139+
"No workflow should be created when the ISAR blob does not exist."
140+
);
141+
Assert.DoesNotContain(_factory.ArgoHttpHandler.Requests, r => r.Method == HttpMethod.Post);
142+
}
143+
125144
[Fact]
126145
public async Task MultiStepChain_SecondWorkflowTriggeredAfterFirstSucceeds()
127146
{

api.Tests/Mocks/BlobStorageServiceMock.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Api.Test.Mocks;
88

99
public class BlobStorageServiceMock : IBlobStorageService
1010
{
11+
public bool BlobExists { get; set; } = true;
12+
1113
public async Task<MemoryStream> DownloadBlobAsync(BlobStorageLocation location)
1214
{
1315
var stream = new MemoryStream();
@@ -36,4 +38,10 @@ public async Task<Uri> CreateReadSasUri(BlobStorageLocation location)
3638
$"https://{location.StorageAccount}.blob.core.windows.net/{location.BlobContainer}/{location.BlobName}?{mockSAS}"
3739
);
3840
}
41+
42+
public async Task<bool> ExistsAsync(BlobStorageLocation location)
43+
{
44+
await Task.CompletedTask;
45+
return BlobExists;
46+
}
3947
}

api.Tests/TestWebApplicationFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class TestWebApplicationFactory<TProgram>(string postgresConnectionString
3636
public RecordingHttpMessageHandler ArgoHttpHandler { get; } = new();
3737
public RecordingEmailService EmailService { get; } = new();
3838
public RecordingTimeseriesService TimeseriesService { get; } = new();
39+
public BlobStorageServiceMock BlobStorageService { get; } = new();
3940

4041
/// <summary>
4142
/// Returns the configured Argo trigger URL for the given workflow type.
@@ -148,7 +149,7 @@ private void ReplaceBlobStorageService(IServiceCollection services)
148149
{
149150
services.Remove(descriptor);
150151
}
151-
services.AddScoped<IBlobStorageService, BlobStorageServiceMock>();
152+
services.AddSingleton<IBlobStorageService>(BlobStorageService);
152153
}
153154

154155
private static void RemoveHostedServices(IServiceCollection services)

0 commit comments

Comments
 (0)