Skip to content

Commit 744ac93

Browse files
authored
[Storage] [WebJobs] Fix tests for GetBlobs changes (Azure#52987)
* [Storage] [WebJobs] Fix tests for GetBlobs changes * Fix formatting * Update ci.functions.yml to point to the correct yml file * Change GetBlobs call to use required parameters over options bag * Change Azure.Storage.Blobs to project reference; Fix mock tests to check for new API
1 parent 13fa942 commit 744ac93

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/src/Config/BlobsExtensionConfigProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ async Task<IEnumerable<T>> IAsyncConverter<MultiBlobContext, IEnumerable<T>>.Con
317317
// sub directories.
318318
string prefix = context.Prefix;
319319
var container = context.Container;
320-
IAsyncEnumerable<BlobItem> blobItems = container.GetBlobsAsync(prefix: prefix, cancellationToken: cancellationToken);
320+
IAsyncEnumerable<BlobItem> blobItems = container.GetBlobsAsync(
321+
traits: BlobTraits.None,
322+
states: BlobStates.None,
323+
prefix: prefix,
324+
cancellationToken: cancellationToken);
321325

322326
// create an IEnumerable<T> of the correct type, performing any required conversions on the blobs
323327
var list = await ConvertBlobs(blobItems, container).ConfigureAwait(false);

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/src/Listeners/BlobLogListener.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ private static async Task GetLogsWithPrefixAsync(List<BlobBaseClient> selectedLo
162162
{
163163
// List the blobs using the prefix
164164
BlobContainerClient container = blobClient.GetBlobContainerClient(LogContainer);
165-
var blobs = container.GetBlobsAsync(traits: BlobTraits.Metadata, prefix: prefix, cancellationToken: cancellationToken).ConfigureAwait(false);
165+
var blobs = container.GetBlobsAsync(
166+
traits: BlobTraits.Metadata,
167+
states: BlobStates.None,
168+
prefix: prefix,
169+
cancellationToken: cancellationToken).ConfigureAwait(false);
166170

167171
// iterate through each blob and figure the start and end times in the metadata
168172
// Type cast to IStorageBlob is safe due to useFlatBlobListing: true above.

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/src/Listeners/PollLogsStrategy.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ private void ScanContainers(object state)
217217
{
218218
// Non-async is correct here. ScanContainers occurs on a background thread. Unless it blocks, no one
219219
// else is around to observe the results.
220-
items = container.GetBlobs(prefix: null, cancellationToken: CancellationToken.None).ToList();
220+
items = container.GetBlobs(
221+
traits: BlobTraits.None,
222+
states: BlobStates.None,
223+
prefix: null,
224+
cancellationToken: CancellationToken.None).ToList();
221225
}
222226
catch (RequestFailedException exception)
223227
{

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/src/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.Azure.WebJobs" />
1616
<PackageReference Include="Microsoft.Extensions.Azure" />
17-
<PackageReference Include="Azure.Storage.Blobs" />
17+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Blobs\src\Azure.Storage.Blobs.csproj" />
18+
<!-- The PackageReference is commented out because Azure.Storage.Blobs is now included via ProjectReference above. -->
19+
<!-- It is retained here until after the next release, and the dependency will be switched back to a PackageReference in the future. -->
20+
<!-- <PackageReference Include="Azure.Storage.Blobs" /> -->
1821
<PackageReference Include="Azure.Storage.Queues" />
1922
</ItemGroup>
2023

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/tests/Listeners/ScanBlobScanLogHybridPollingStrategyTests.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,31 @@ public void Setup()
7373
{
7474
return new TestAsyncPageable<BlobItem>(_blobItems);
7575
});
76+
_blobContainerMock.Setup(x => x.GetBlobsAsync(It.IsAny<GetBlobsOptions>(), It.IsAny<CancellationToken>()))
77+
.Returns(() =>
78+
{
79+
return new TestAsyncPageable<BlobItem>(_blobItems);
80+
});
7681
_secondBlobContainerMock.Setup(x => x.GetBlobsAsync(It.IsAny<BlobTraits>(), It.IsAny<BlobStates>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
7782
.Returns(() =>
7883
{
7984
return new TestAsyncPageable<BlobItem>(_secondBlobItems);
8085
});
86+
_secondBlobContainerMock.Setup(x => x.GetBlobsAsync(It.IsAny<GetBlobsOptions>(), It.IsAny<CancellationToken>()))
87+
.Returns(() =>
88+
{
89+
return new TestAsyncPageable<BlobItem>(_secondBlobItems);
90+
});
8191
_logsContainerMock.Setup(x => x.GetBlobsAsync(It.IsAny<BlobTraits>(), It.IsAny<BlobStates>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
8292
.Returns(() =>
8393
{
8494
return new TestAsyncPageable<BlobItem>(new List<BlobItem>());
8595
});
96+
_logsContainerMock.Setup(x => x.GetBlobsAsync(It.IsAny<GetBlobsOptions>(), It.IsAny<CancellationToken>()))
97+
.Returns(() =>
98+
{
99+
return new TestAsyncPageable<BlobItem>(new List<BlobItem>());
100+
});
86101
}
87102

88103
[Test]
@@ -231,7 +246,7 @@ public void BlobPolling_IgnoresClockSkew()
231246
// We should see the new item. We'll see 2 blobs, but only process 1 (due to receipt).
232247
RunExecuterWithExpectedBlobs(expectedNames, product, executor, 1);
233248

234-
_blobContainerMock.Verify(x => x.GetBlobsAsync(It.IsAny<BlobTraits>(), It.IsAny<BlobStates>(), It.IsAny<string>(), It.IsAny<CancellationToken>()),
249+
_blobContainerMock.Verify(x => x.GetBlobsAsync(It.IsAny<GetBlobsOptions>(), It.IsAny<CancellationToken>()),
235250
Times.Exactly(2));
236251
Assert.AreEqual(expectedNames, executor.BlobReceipts);
237252
}
@@ -269,7 +284,7 @@ public void BlobPolling_IncludesPreviousBatch()
269284
// We should see the new item. We'll see 2 blobs, but only process 1 (due to receipt).
270285
RunExecuterWithExpectedBlobs(expectedNames, product, executor, 1);
271286

272-
_blobContainerMock.Verify(x => x.GetBlobsAsync(It.IsAny<BlobTraits>(), It.IsAny<BlobStates>(), It.IsAny<string>(), It.IsAny<CancellationToken>()),
287+
_blobContainerMock.Verify(x => x.GetBlobsAsync(It.IsAny<GetBlobsOptions>(), It.IsAny<CancellationToken>()),
273288
Times.Exactly(2));
274289
Assert.AreEqual(expectedNames, executor.BlobReceipts);
275290
}
@@ -391,7 +406,7 @@ public async Task ExecuteAsync_UpdatesScanInfo_WithEarliestFailure()
391406
DateTime? storedTime = await testScanInfoManager.LoadLatestScanAsync(accountName, ContainerName);
392407
Assert.True(storedTime < earliestErrorTime);
393408
Assert.AreEqual(1, testScanInfoManager.UpdateCounts[accountName][ContainerName]);
394-
_blobContainerMock.Verify(x => x.GetBlobsAsync(It.IsAny<BlobTraits>(), It.IsAny<BlobStates>(), It.IsAny<string>(), It.IsAny<CancellationToken>()),
409+
_blobContainerMock.Verify(x => x.GetBlobsAsync(It.IsAny<GetBlobsOptions>(), It.IsAny<CancellationToken>()),
395410
Times.Exactly(2));
396411
}
397412

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Scenario.Tests/tests/MultipleStorageAccountsEndToEndTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using System;
55
using System.IO;
66
using System.Linq;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
using Azure.Core.TestFramework;
910
using Azure.Storage.Blobs;
11+
using Azure.Storage.Blobs.Models;
1012
using Azure.Storage.Blobs.Specialized;
1113
using Azure.Storage.Queues;
1214
using Azure.Storage.Queues.Models;
@@ -51,7 +53,11 @@ public async Task BlobToBlob_DifferentAccounts_PrimaryToSecondary_Succeeds()
5153

5254
await TestHelpers.Await(async () =>
5355
{
54-
var pageable = _fixture.OutputContainer2.GetBlobsAsync(prefix: "blob1");
56+
var pageable = _fixture.OutputContainer2.GetBlobsAsync(
57+
traits: BlobTraits.None,
58+
states: BlobStates.None,
59+
prefix: "blob1",
60+
cancellationToken: CancellationToken.None);
5561
var enumerator = pageable.GetAsyncEnumerator();
5662
var result = await enumerator.MoveNextAsync() && enumerator.Current.Properties.ContentLength > 0;
5763
if (result)

sdk/storage/ci.functions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pr:
1010
- release/*
1111
paths:
1212
include:
13-
- sdk/storage/ci.webjobs.yml
13+
- sdk/storage/ci.functions.yml
1414
- sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage/
1515
- sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Blobs/
1616
- sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Common/

0 commit comments

Comments
 (0)