Skip to content

Commit 15d21bf

Browse files
authored
[release/8.0] Use TokenCredential for Cosmos tests (#33966)
1 parent 67fd137 commit 15d21bf

15 files changed

Lines changed: 178 additions & 31 deletions

‎All.sln‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
Microsoft Visual Studio Solution File, Format Version 12.00
32
# Visual Studio Version 17
43
VisualStudioVersion = 17.0.31521.260
54
MinimumVisualStudioVersion = 17.0.31521.260

‎azure-pipelines.yml‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ extends:
120120
- script: eng\common\cibuild.cmd -configuration $(_BuildConfig) -prepareMachine $(_InternalBuildArgs) $(_InternalRuntimeDownloadArgs) $(_AdditionalBuildArgs)
121121
env:
122122
Test__Cosmos__DefaultConnection: $(_CosmosConnectionUrl)
123-
name: Build
123+
displayName: Build
124124
templateContext:
125125
outputs:
126126
- output: pipelineArtifact
@@ -131,7 +131,7 @@ extends:
131131
- job: macOS
132132
pool:
133133
name: Azure Pipelines
134-
image: macOS-11
134+
image: macOS-12
135135
os: macOS
136136
variables:
137137
# Rely on task Arcade injects, not auto-injected build step.
@@ -149,7 +149,7 @@ extends:
149149
Test__Cosmos__DefaultConnection: $(_CosmosConnectionUrl)
150150
# Work-around for https://github.com/dotnet/runtime/issues/70758
151151
COMPlus_EnableWriteXorExecute: 0
152-
name: Build
152+
displayName: Build
153153
templateContext:
154154
outputs:
155155
- output: pipelineArtifact
@@ -172,12 +172,10 @@ extends:
172172
steps:
173173
- bash: |
174174
echo "##vso[task.setvariable variable=_CosmosConnectionUrl]https://ef-nightly-test.documents.azure.com:443/"
175-
echo "##vso[task.setvariable variable=_CosmosToken]$(ef-nightly-cosmos-key)"
176175
displayName: Prepare to run Cosmos tests on ef-nightly-test
177176
condition: and(eq(variables['_CosmosConnectionUrl'], 'true'), or(endsWith(variables['_runCounter'], '0'), endsWith(variables['_runCounter'], '2'), endsWith(variables['_runCounter'], '4'), endsWith(variables['_runCounter'], '6'), endsWith(variables['_runCounter'], '8')))
178177
- bash: |
179178
echo "##vso[task.setvariable variable=_CosmosConnectionUrl]https://ef-pr-test.documents.azure.com:443/"
180-
echo "##vso[task.setvariable variable=_CosmosToken]$(ef-pr-cosmos-test)"
181179
displayName: Prepare to run Cosmos tests on ef-pr-test
182180
condition: and(eq(variables['_CosmosConnectionUrl'], 'true'), or(endsWith(variables['_runCounter'], '1'), endsWith(variables['_runCounter'], '3'), endsWith(variables['_runCounter'], '5'), endsWith(variables['_runCounter'], '7'), endsWith(variables['_runCounter'], '9')))
183181
- task: Bash@3
@@ -188,10 +186,20 @@ extends:
188186
env:
189187
Token: $(dn-bot-dnceng-artifact-feeds-rw)
190188
- script: eng/common/cibuild.sh --configuration $(_BuildConfig) --prepareMachine $(_InternalRuntimeDownloadArgs)
189+
displayName: Build
190+
- task: AzureCLI@2
191+
displayName: Run Cosmos tests
192+
inputs:
193+
azureSubscription: EFCosmosTesting
194+
scriptType: bash
195+
scriptLocation: 'inlineScript'
196+
inlineScript: |
197+
./test.sh --ci --configuration $(_BuildConfig) --projects $(Build.SourcesDirectory)/test/EFCore.Cosmos.FunctionalTests/EFCore.Cosmos.FunctionalTests.csproj
191198
env:
192199
Test__Cosmos__DefaultConnection: $(_CosmosConnectionUrl)
193-
Test__Cosmos__AuthToken: $(_CosmosToken)
194-
name: Build
200+
Test__Cosmos__UseTokenCredential: true
201+
Test__Cosmos__SubscriptionId: d709b837-4a74-4aec-addc-b6e4b9b23e7e
202+
Test__Cosmos__ResourceGroup: efcosmosci
195203
templateContext:
196204
outputs:
197205
- output: pipelineArtifact

‎eng/Versions.props‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@
3838
<!-- NB: This version affects Visual Studio compatibility. See https://learn.microsoft.com/visualstudio/extensibility/roslyn-version-support -->
3939
<MicrosoftCodeAnalysisVersion>4.5.0</MicrosoftCodeAnalysisVersion>
4040
<MicrosoftCodeAnalysisTestingVersion>1.1.2-beta1.24121.1</MicrosoftCodeAnalysisTestingVersion>
41+
<AzureIdentityVersion>1.11.3</AzureIdentityVersion>
42+
<AzureResourceManagerCosmosDBVersion>1.3.2</AzureResourceManagerCosmosDBVersion>
4143
</PropertyGroup>
4244
</Project>

‎test/EFCore.Cosmos.FunctionalTests/ConfigPatternsCosmosTest.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// ReSharper disable UnusedAutoPropertyAccessor.Local
77
namespace Microsoft.EntityFrameworkCore.Cosmos;
88

9+
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
910
public class ConfigPatternsCosmosTest : IClassFixture<ConfigPatternsCosmosTest.CosmosFixture>
1011
{
1112
private const string DatabaseName = "ConfigPatternsCosmos";

‎test/EFCore.Cosmos.FunctionalTests/ConnectionSpecificationTest.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Microsoft.EntityFrameworkCore.Cosmos;
88

9+
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
910
public class ConnectionSpecificationTest
1011
{
1112
[ConditionalFact]

‎test/EFCore.Cosmos.FunctionalTests/CosmosConcurrencyTest.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Microsoft.EntityFrameworkCore.Cosmos;
55

6+
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
67
public class CosmosConcurrencyTest : IClassFixture<CosmosConcurrencyTest.CosmosFixture>
78
{
89
private const string DatabaseName = "CosmosConcurrencyTest";

‎test/EFCore.Cosmos.FunctionalTests/EFCore.Cosmos.FunctionalTests.csproj‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
<ItemGroup>
5757
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesVersion)" />
5858
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsConfigurationJsonVersion)" />
59-
<PackageReference Include="Azure.Identity" Version="1.10.2" />
59+
<PackageReference Include="Azure.Identity" Version="$(AzureIdentityVersion)" />
60+
<PackageReference Include="Azure.ResourceManager.CosmosDB" Version="$(AzureResourceManagerCosmosDBVersion)" />
6061
</ItemGroup>
6162

6263
</Project>

‎test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ public virtual async Task Can_use_non_int_keys_for_embedded_entities()
498498
Guid addressGuid;
499499
await using (var context = new EmbeddedTransportationContext(options))
500500
{
501-
await context.Database.EnsureCreatedAsync();
502501
var person = new Person { Id = 1 };
503502
address = new Address { Street = "Second", City = "Village" };
504503
person.Addresses.Add(address);

‎test/EFCore.Cosmos.FunctionalTests/Internal/CosmosDatabaseCreatorTest.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
55

6+
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
67
public class CosmosDatabaseCreatorTest
78
{
89
public static IEnumerable<object[]> IsAsyncData = new[]

‎test/EFCore.Cosmos.FunctionalTests/ReloadTest.cs‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Azure.Core;
45
using Newtonsoft.Json.Linq;
56

67
namespace Microsoft.EntityFrameworkCore.Cosmos;
@@ -43,21 +44,35 @@ public class ReloadTestContext : DbContext
4344
private readonly string _connectionUri;
4445
private readonly string _authToken;
4546
private readonly string _name;
47+
private readonly TokenCredential _tokenCredential;
4648

4749
public ReloadTestContext(CosmosTestStore testStore)
4850
{
4951
_connectionUri = testStore.ConnectionUri;
5052
_authToken = testStore.AuthToken;
5153
_name = testStore.Name;
54+
_tokenCredential = testStore.TokenCredential;
5255
}
5356

5457
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
55-
=> optionsBuilder
56-
.UseCosmos(
57-
_connectionUri,
58-
_authToken,
59-
_name,
60-
b => b.ApplyConfiguration());
58+
{
59+
if (TestEnvironment.UseTokenCredential)
60+
{
61+
optionsBuilder.UseCosmos(
62+
_connectionUri,
63+
_tokenCredential,
64+
_name,
65+
b => b.ApplyConfiguration());
66+
}
67+
else
68+
{
69+
optionsBuilder.UseCosmos(
70+
_connectionUri,
71+
_authToken,
72+
_name,
73+
b => b.ApplyConfiguration());
74+
}
75+
}
6176

6277
protected override void OnModelCreating(ModelBuilder modelBuilder)
6378
{

0 commit comments

Comments
 (0)