Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
90 changes: 52 additions & 38 deletions Aspire.sln

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Aspire.Hosting.Redis/Aspire.Hosting.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
Copy link
Member Author

Choose a reason for hiding this comment

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

We should aim to remove this.

<InternalsVisibleTo Include="Aspire.Hosting.Redis.Tests" />
Copy link
Member

Choose a reason for hiding this comment

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

@sebastienros - can we remove this? What is it needed for?

Copy link
Member

@sebastienros sebastienros Jul 9, 2024

Choose a reason for hiding this comment

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

RedisContainerImageTags
RedisCommanderConfigWriterHook

Are used in these tests and internal.
This is why Aspire.Hosting.Tests was already listed, because these tests are coming from this project (moved to this new Aspire.Hosting.Redis.Tests)

</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Aspire.Hosting/Aspire.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

<ItemGroup>
<InternalsVisibleTo Include="Aspire.Hosting.Tests" />
<InternalsVisibleTo Include="Aspire.Hosting.Redis.Tests" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions tests/Aspire.Hosting.Redis.Tests/Aspire.Hosting.Redis.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsAspireHost>true</IsAspireHost>
<!--
CS8002: Referenced assembly does not have a strong name. MongoDB.Driver package is unsigned, we ignore that warning on purpose
-->
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.csproj" IsAspireProjectResource="false" />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" />
<ProjectReference Include="..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.csproj" />

Are these needed? This project doesn't have <IsAspireHost>true</IsAspireHost>

Copy link
Member

Choose a reason for hiding this comment

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

Works as you suggest


<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Newtonsoft.Json.Schema" />

<Compile Include="$(TestsSharedDir)Logging\*.cs" LinkBase="shared/Logging" />

<Compile Include="..\Aspire.Hosting.Tests\Utils\ArgumentEvaluator.cs" Link="Utils\ArgumentEvaluator.cs" />
<Compile Include="..\Aspire.Hosting.Tests\Utils\EnvironmentVariableEvaluator.cs" Link="Utils\EnvironmentVariableEvaluator.cs" />
<Compile Include="..\Aspire.Hosting.Tests\Utils\FileUtil.cs" Link="Utils\FileUtil.cs" />
<Compile Include="..\Aspire.Hosting.Tests\Utils\ManifestUtils.cs" Link="Utils\ManifestUtils.cs" />
<Compile Include="..\Aspire.Hosting.Tests\Utils\TestDistributedApplicationBuilder.cs" Link="Utils\TestDistributedApplicationBuilder.cs" />

<Content Include="$(RepoRoot)src\Schema\aspire-8.0.json" Link="Schema\aspire-8.0.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Folder Include="Utils\" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions tests/Aspire.Hosting.Redis.Tests/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
<Import Project="../../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.props" />

</Project>
8 changes: 8 additions & 0 deletions tests/Aspire.Hosting.Redis.Tests/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
<Import Project="..\..\src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void WithDataVolumeAddsVolumeAnnotation(bool? isReadOnly)

var volumeAnnotation = redis.Resource.Annotations.OfType<ContainerMountAnnotation>().Single();

Assert.Equal("Aspire.Hosting.Tests-myRedis-data", volumeAnnotation.Source);
Assert.Equal("Aspire.Hosting.Redis.Tests-myRedis-data", volumeAnnotation.Source);
Assert.Equal("/data", volumeAnnotation.Target);
Assert.Equal(ContainerMountType.Volume, volumeAnnotation.Type);
Assert.Equal(isReadOnly ?? false, volumeAnnotation.IsReadOnly);
Expand Down
6 changes: 6 additions & 0 deletions tests/Aspire.Hosting.Redis.Tests/XunitAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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.Redis;
using Aspire.Hosting.Utils;
using Xunit;

Expand Down Expand Up @@ -54,8 +53,8 @@ public void WithImageMutatesImageNameOfLastAnnotation()
public void WithImageTagMutatesImageTag()
{
using var builder = TestDistributedApplicationBuilder.Create();
var redis = builder.AddRedis("redis").WithImageTag(RedisContainerImageTags.Tag);
Assert.Equal(RedisContainerImageTags.Tag, redis.Resource.Annotations.OfType<ContainerImageAnnotation>().Single().Tag);
var redis = builder.AddRedis("redis").WithImageTag("7.1");
Assert.Equal("7.1", redis.Resource.Annotations.OfType<ContainerImageAnnotation>().Single().Tag);
}

[Fact]
Expand All @@ -80,7 +79,7 @@ public void WithImageTagThrowsIfNoImageAnnotation()
using var builder = TestDistributedApplicationBuilder.Create();
var container = builder.AddResource(new TestContainerResource("testcontainer"));

var exception = Assert.Throws<InvalidOperationException>(() => container.WithImageTag(RedisContainerImageTags.Tag));
var exception = Assert.Throws<InvalidOperationException>(() => container.WithImageTag("7.1"));
Assert.Equal("The resource 'testcontainer' does not have a container image specified. Use WithImage to specify the container image and tag.", exception.Message);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public async Task WithContainerRegistryUpdatesContainerImageAnnotationsDuringPub
ContainerRegistryOverride = "myprivateregistry.company.com"
});

var redis = builder.AddRedis("redis");
var redis = builder.AddContainer("redis", "redis");
builder.Build().Run();

var redisManifest = await ManifestUtils.GetManifest(redis.Resource);
var expectedManifest = $$"""
{
"type": "container.v0",
"connectionString": "{redis.bindings.tcp.host}:{redis.bindings.tcp.port}",
"image": "myprivateregistry.company.com/{{RedisContainerImageTags.Image}}:{{RedisContainerImageTags.Tag}}",
"image": "myprivateregistry.company.com/redis:latest",
"bindings": {
"tcp": {
"scheme": "tcp",
Expand Down