Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Aspire.Hosting.SqlServer.Tests project #5056

Merged
merged 35 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b36fb87
Extract Aspire.Hosting.SqlServer.Tests project
Alirexaa Jul 24, 2024
40eb24f
Merge branch 'main' into sqlserver-tests
Alirexaa Jul 29, 2024
ce7a44d
apply suggsted changes
Alirexaa Jul 29, 2024
b0fbb8b
Merge branch 'main' into sqlserver-tests
Alirexaa Jul 29, 2024
f9b0dc8
Merge remote-tracking branch 'origin/main' into sqlserver-tests
sebastienros Aug 2, 2024
5c1e695
Wait for database server to stop between mounts
sebastienros Aug 2, 2024
a5335de
Try /data for data bind mount
sebastienros Aug 2, 2024
87cfbe5
Mount specific folders
sebastienros Aug 2, 2024
dbc21e1
Merge remote-tracking branch 'origin/main' into sqlserver-tests
sebastienros Aug 2, 2024
5c4251b
Update permission on Linux
sebastienros Aug 2, 2024
23d613b
Simplify and add VerifyEfResource
sebastienros Aug 2, 2024
4cbb62f
Last attempt at setting correct persmissions
sebastienros Aug 3, 2024
ecce22e
Skip WithDataBindMount on CI
sebastienros Aug 3, 2024
57e32d7
Remove previous functional tests
sebastienros Aug 3, 2024
25c24e6
Only skip file mount on CI
sebastienros Aug 5, 2024
1e655ac
Comment for container registry
sebastienros Aug 5, 2024
d4fd56d
Update tests/testproject/TestProject.IntegrationServiceA/TestProject.…
sebastienros Aug 5, 2024
709d2b3
Update tests/Aspire.Hosting.SqlServer.Tests/Aspire.Hosting.SqlServer.…
sebastienros Aug 5, 2024
44e2814
Update tests/Aspire.Hosting.SqlServer.Tests/SqlServerFunctionalTests.cs
sebastienros Aug 5, 2024
c7f117b
Update tests/Aspire.Hosting.SqlServer.Tests/TestDbContext.cs
sebastienros Aug 5, 2024
953eb94
Test permissions on CI
sebastienros Aug 5, 2024
4f82649
Adapt permissions on non-Windows only
sebastienros Aug 5, 2024
3b987b2
Merge VerifySqlServerResource
sebastienros Aug 6, 2024
7938a1b
Use SetUnixFileMode instead of chmod
sebastienros Aug 6, 2024
9b72989
Update tests/Aspire.Hosting.SqlServer.Tests/SqlServerFunctionalTests.cs
sebastienros Aug 6, 2024
450fc9d
Merge branch 'main' into sqlserver-tests
sebastienros Aug 6, 2024
ddbc5ce
Use EnsureCreatedAsync
sebastienros Aug 6, 2024
88e6982
Adapt retry delays
sebastienros Aug 6, 2024
97df947
Adapt required permisions for folder mounts
sebastienros Aug 6, 2024
dd1871d
Merge remote-tracking branch 'origin/main' into sqlserver-tests
sebastienros Aug 6, 2024
327ff0b
React to testing changes in main
sebastienros Aug 6, 2024
5c150ce
Don't use test registry
sebastienros Aug 7, 2024
c8e3e20
Fix retry pattern
sebastienros Aug 7, 2024
170a349
Merge remote-tracking branch 'origin/main' into sqlserver-tests
sebastienros Aug 8, 2024
4736118
Merge remote-tracking branch 'origin/main' into sqlserver-tests
sebastienros Aug 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.PostgreSQL.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Qdrant.Tests", "tests\Aspire.Hosting.Qdrant.Tests\Aspire.Hosting.Qdrant.Tests.csproj", "{8E2AA85E-C351-47B4-AF91-58557FAD5840}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Milvus.Tests", "tests\Aspire.Hosting.Milvus.Tests\Aspire.Hosting.Milvus.Tests.csproj", "{986886B7-0E38-4890-92C3-5B46DE322DAF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Milvus.Tests", "tests\Aspire.Hosting.Milvus.Tests\Aspire.Hosting.Milvus.Tests.csproj", "{986886B7-0E38-4890-92C3-5B46DE322DAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.MySql.Tests", "tests\Aspire.Hosting.MySql.Tests\Aspire.Hosting.MySql.Tests.csproj", "{F3F33CF8-A2BB-4351-8501-A6884C5126FE}"
EndProject
Expand Down Expand Up @@ -543,6 +543,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Keycloak.Authenticat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Nats.Tests", "tests\Aspire.Hosting.Nats.Tests\Aspire.Hosting.Nats.Tests.csproj", "{F492357C-682E-4CBB-A374-1A124B3976A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.SqlServer.Tests", "tests\Aspire.Hosting.SqlServer.Tests\Aspire.Hosting.SqlServer.Tests.csproj", "{D705FE42-CD54-4575-BA18-0431256B40B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Azure.Tests", "tests\Aspire.Hosting.Azure.Tests\Aspire.Hosting.Azure.Tests.csproj", "{8691F993-7B19-496E-B8E1-EF1199ACF2E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestShop.AppHost", "playground\TestShop\TestShop.AppHost\TestShop.AppHost.csproj", "{DB3E1AD8-87F6-414D-B46F-A0DC334AECCD}"
Expand Down Expand Up @@ -1439,6 +1441,10 @@ Global
{F492357C-682E-4CBB-A374-1A124B3976A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F492357C-682E-4CBB-A374-1A124B3976A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F492357C-682E-4CBB-A374-1A124B3976A3}.Release|Any CPU.Build.0 = Release|Any CPU
{D705FE42-CD54-4575-BA18-0431256B40B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D705FE42-CD54-4575-BA18-0431256B40B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D705FE42-CD54-4575-BA18-0431256B40B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D705FE42-CD54-4575-BA18-0431256B40B2}.Release|Any CPU.Build.0 = Release|Any CPU
{8691F993-7B19-496E-B8E1-EF1199ACF2E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8691F993-7B19-496E-B8E1-EF1199ACF2E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8691F993-7B19-496E-B8E1-EF1199ACF2E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1728,6 +1734,7 @@ Global
{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7} = {C424395C-1235-41A4-BF55-07880A04368C}
{F492357C-682E-4CBB-A374-1A124B3976A3} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{D705FE42-CD54-4575-BA18-0431256B40B2} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{8691F993-7B19-496E-B8E1-EF1199ACF2E1} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{DB3E1AD8-87F6-414D-B46F-A0DC334AECCD} = {A68BA1A5-1604-433D-9778-DC0199831C2A}
{D537CF4D-DF30-41C7-B4F9-FEB152A19BE7} = {57A42144-739E-49A7-BADB-BB8F5F20FA17}
Expand Down
18 changes: 17 additions & 1 deletion src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,21 @@ public static IResourceBuilder<SqlServerServerResource> WithDataVolume(this IRes
/// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<SqlServerServerResource> WithDataBindMount(this IResourceBuilder<SqlServerServerResource> builder, string source, bool isReadOnly = false)
=> builder.WithBindMount(source, "/var/opt/mssql", isReadOnly);
{
// c.f. https://learn.microsoft.com/sql/linux/sql-server-linux-docker-container-configure?view=sql-server-ver15&pivots=cs1-bash#mount-a-host-directory-as-data-volume
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this done only for WithDataBindMount and not for WithDataVolume?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding specific folders only applies to folder mounts, not volumes. Volumes just work fine locally without changes, and the documentation only uses it for folders mounts too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwestMSFT - I see you wrote the documentation being referenced here in MicrosoftDocs/sql-docs@51dddc6. Is there a reason we need to split all 3 directories when binding to a host directory, but when using a docker volume you just need a single volume? Why doesn't it work to map the single top-level /var/opt/mssql directory to the host machine?

cc @JerryNixon

Copy link

@rwestMSFT rwestMSFT Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt My name appears on thousands of articles. Please refer to the author in metadata when reviewing SQL Docs content.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amitkh-msft - Looks like you are the "author" of the article referenced above. Any chance you can answer the above question?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. Sure, please give me some time. I will look at this and try to answer the question.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts @amitkh-msft? Why can't we just bind mount to the root directory instead of the 3 separate ones?


foreach (var dir in new string[] { "data", "log", "secrets" })
{
var path = Path.Combine(source, dir);

if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}

builder.WithBindMount(path, $"/var/opt/mssql/{dir}", isReadOnly);
}

return builder;
}
}
5 changes: 1 addition & 4 deletions tests/Aspire.EndToEnd.Tests/IntegrationServicesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public Task DumpComponentLogsAsync(TestResourceNames resource, ITestOutputHelper
TestResourceNames.oracledatabase => "oracledatabase",
TestResourceNames.postgres or TestResourceNames.efnpgsql => "postgres",
TestResourceNames.redis => "redis",
TestResourceNames.sqlserver or TestResourceNames.efsqlserver => "sqlserver",
_ => throw new ArgumentException($"Unknown resource: {resource}")
};

Expand Down Expand Up @@ -144,9 +143,7 @@ private static TestResourceNames GetResourcesToSkip()
"basicservices" => TestResourceNames.mongodb
| TestResourceNames.redis
| TestResourceNames.postgres
| TestResourceNames.efnpgsql
| TestResourceNames.sqlserver
| TestResourceNames.efsqlserver,
| TestResourceNames.efnpgsql,
"" or null => TestResourceNames.All,
_ => throw new ArgumentException($"Unknown test scenario '{TestScenario}'")
};
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.EndToEnd.Tests/IntegrationServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public IntegrationServicesTests(ITestOutputHelper testOutput, IntegrationService
[InlineData(TestResourceNames.postgres)]
[InlineData(TestResourceNames.efnpgsql)]
[InlineData(TestResourceNames.redis)]
[InlineData(TestResourceNames.sqlserver)]
[InlineData(TestResourceNames.efsqlserver)]
public Task VerifyComponentWorks(TestResourceNames resourceName)
=> RunTestAsync(async () =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Tests.Utils;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Sockets;
using Xunit;

namespace Aspire.Hosting.Tests.SqlServer;
namespace Aspire.Hosting.SqlServer.Tests;

public class AddSqlServerTests
{
Expand All @@ -18,7 +19,7 @@ public void AddSqlServerAddsGeneratedPasswordParameterWithUserSecretsParameterDe

var sql = appBuilder.AddSqlServer("sql");

Assert.IsType<UserSecretsParameterDefault>(sql.Resource.PasswordParameter.Default);
Assert.Equal("Aspire.Hosting.ApplicationModel.UserSecretsParameterDefault", sql.Resource.PasswordParameter.Default?.GetType().FullName);
}

[Fact]
Expand All @@ -28,7 +29,7 @@ public void AddSqlServerDoesNotAddGeneratedPasswordParameterWithUserSecretsParam

var sql = appBuilder.AddSqlServer("sql");

Assert.IsNotType<UserSecretsParameterDefault>(sql.Resource.PasswordParameter.Default);
Assert.NotEqual("Aspire.Hosting.ApplicationModel.UserSecretsParameterDefault", sql.Resource.PasswordParameter.Default?.GetType().FullName);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" />
sebastienros marked this conversation as resolved.
Show resolved Hide resolved
<ProjectReference Include="..\..\src\Aspire.Hosting.SqlServer\Aspire.Hosting.SqlServer.csproj" />
<ProjectReference Include="..\..\src\Components\Aspire.Microsoft.Data.SqlClient\Aspire.Microsoft.Data.SqlClient.csproj" />
<ProjectReference Include="..\..\src\Components\Aspire.Microsoft.EntityFrameworkCore.SqlServer\Aspire.Microsoft.EntityFrameworkCore.SqlServer.csproj" />
<ProjectReference Include="..\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)src\Aspire.Hosting.SqlServer\SqlServerContainerImageTags.cs" />
<Compile Include="$(SharedDir)VolumeNameGenerator.cs" Link="Utils\VolumeNameGenerator.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Testing\ResourceLoggerForwarderService.cs" Link="Utils\ResourceLoggerForwarderService.cs" />
</ItemGroup>

</Project>
Loading
Loading