Skip to content

Commit

Permalink
[tests] Allow ConfigurationSchema.json tests to run out of repo (#1790)
Browse files Browse the repository at this point in the history
* [tests] ConformanceTests: Remove dependency on GetRepoRoot

.. by changing the tests to expect `ConfigurationSchema.json` to be
available next to the test assembly.

* [tests] Deploy ConfigurationSchema.json to the test output dir

* [tests] Avoid redundant tests in Redis Caching tests

Both `Aspire.StackExchange.Redis.DistributedCaching`, and
`Aspire.StackExchange.Redis.OutputCaching` have
`ConfigurationSchema.json` which reference `Aspire.StackExchange.Redis`
without adding anything more.

But the tests for those two run validation for the
`Aspire.StackExchange.Redis` schema, which is already done by the main
tests. Instead of that:

- `Aspire.StackExchange.Redis` - continue doing the validation tests
- `Aspire.StackExchange.Redis.{Output,Distributed}Caching`
    - Run the validation test for the schema against the the project's
      own schema
    - And don't check for any invalid cases since there is nothing being
      added in the schema

* Address review feedback from @ eerhardt to make path separators consistent in csproj
  • Loading branch information
radical authored Jan 24, 2024
1 parent 6ad259d commit dff1467
Show file tree
Hide file tree
Showing 42 changed files with 54 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Azure.AI.OpenAI\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Azure.AI.OpenAI\Aspire.Azure.AI.OpenAI.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.Azure.AI.OpenAI.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class ConformanceTests : ConformanceTests<OpenAIClient, AzureOpenAISettin

protected override bool SupportsKeyedRegistrations => true;

protected override string JsonSchemaPath => "src/Components/Aspire.Azure.AI.OpenAI/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Azure.Data.Tables\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Azure.Data.Tables\Aspire.Azure.Data.Tables.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.Azure.Data.Tables.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class ConformanceTests : ConformanceTests<TableServiceClient, AzureDataTa

protected override string ActivitySourceName => "Azure.Data.Tables.TableServiceClient";

protected override string JsonSchemaPath => "src/Components/Aspire.Azure.Data.Tables/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Azure.Messaging.ServiceBus\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Azure.Messaging.ServiceBus\Aspire.Azure.Messaging.ServiceBus.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public abstract class ConformanceTests : ConformanceTests<ServiceBusClient, Azur

protected override bool SupportsKeyedRegistrations => true;

protected override string JsonSchemaPath => "src/Components/Aspire.Azure.Messaging.ServiceBus/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Azure.Security.KeyVault\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Azure.Security.KeyVault\Aspire.Azure.Security.KeyVault.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class ConformanceTests : ConformanceTests<SecretClient, AzureSecurityKeyV

protected override bool CanConnectToServer => s_canConnectToServer.Value;

protected override string JsonSchemaPath => "src/Components/Aspire.Azure.Security.KeyVault/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Azure.Storage.Blobs\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Azure.Storage.Blobs\Aspire.Azure.Storage.Blobs.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.Azure.Storage.Blobs.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class ConformanceTests : ConformanceTests<BlobServiceClient, AzureStorage

protected override bool CanConnectToServer => s_canConnectToServer.Value;

protected override string JsonSchemaPath => "src/Components/Aspire.Azure.Storage.Blobs/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Azure.Storage.Queues\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Azure.Storage.Queues\Aspire.Azure.Storage.Queues.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.Azure.Storage.Queues.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class ConformanceTests : ConformanceTests<QueueServiceClient, AzureStorag

protected override bool CanConnectToServer => s_canConnectToServer.Value;

protected override string JsonSchemaPath => "src/Components/Aspire.Azure.Storage.Queues/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
34 changes: 5 additions & 29 deletions tests/Aspire.Components.Common.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class ConformanceTests<TService, TOptions>

protected abstract string ActivitySourceName { get; }

protected abstract string JsonSchemaPath { get; }
protected string JsonSchemaPath => Path.Combine(AppContext.BaseDirectory, "ConfigurationSchema.json");

protected virtual string ValidJsonConfig { get; } = string.Empty;

Expand Down Expand Up @@ -316,25 +316,21 @@ public async Task HealthCheckReportsExpectedStatus(string? key)
Assert.Contains(healthReport.Entries, entry => entry.Value.Status == expected);
}

[ConditionalFact]
[Fact]
public void ConfigurationSchemaValidJsonConfigTest()
{
SkipIfJsonSchemaPathNotSet();

var schema = JsonSchema.FromFile(Path.Combine(GetRepoRoot(), JsonSchemaPath));
var schema = JsonSchema.FromFile(JsonSchemaPath);
var config = JsonNode.Parse(ValidJsonConfig);

var results = schema.Evaluate(config);

Assert.True(results.IsValid);
}

[ConditionalFact]
[Fact]
public void ConfigurationSchemaInvalidJsonConfigTest()
{
SkipIfJsonSchemaPathNotSet();

var schema = JsonSchema.FromFile(Path.Combine(GetRepoRoot(), JsonSchemaPath));
var schema = JsonSchema.FromFile(JsonSchemaPath);

foreach ((string json, string error) in InvalidJsonToErrorMessage)
{
Expand All @@ -347,14 +343,6 @@ public void ConfigurationSchemaInvalidJsonConfigTest()
}
}

private void SkipIfJsonSchemaPathNotSet()
{
if (string.IsNullOrEmpty(JsonSchemaPath))
{
throw new SkipTestException("ConfigurationSchema.json path not set.");
}
}

/// <summary>
/// Ensures that when the connection information is missing, an exception isn't thrown before the host
/// is built, so any exception can be logged with ILogger.
Expand All @@ -379,18 +367,6 @@ key is null
: host.Services.GetRequiredKeyedService<TService>(key));
}

private static string GetRepoRoot()
{
string directory = AppContext.BaseDirectory;

while (directory != null && !Directory.Exists(Path.Combine(directory, ".git")))
{
directory = Directory.GetParent(directory)!.FullName;
}

return directory!;
}

protected virtual void SetupConnectionInformationIsDelayValidated() { }

// This method can have side effects (setting AppContext switch, enabling activity source by name).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Confluent.Kafka\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Confluent.Kafka\Aspire.Confluent.Kafka.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class ConsumerConformanceTests : ConformanceTests<IConsumer<string, strin

protected override string ActivitySourceName => throw new NotImplementedException();

protected override string JsonSchemaPath => "src/Components/Aspire.Confluent.Kafka/ConfigurationSchema.json";

protected override string[] RequiredLogCategories => [
"Aspire.Confluent.Kafka"
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class ProducerConformanceTests : ConformanceTests<IProducer<string, strin

protected override string ActivitySourceName => throw new NotImplementedException();

protected override string JsonSchemaPath => "src/Components/Aspire.Confluent.Kafka/ConfigurationSchema.json";

protected override string[] RequiredLogCategories => [
"Aspire.Confluent.Kafka"
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Microsoft.Azure.Cosmos\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Microsoft.Azure.Cosmos\Aspire.Microsoft.Azure.Cosmos.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions tests/Aspire.Microsoft.Azure.Cosmos.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ protected override void SetTracing(AzureCosmosDBSettings options, bool enabled)
protected override void SetMetrics(AzureCosmosDBSettings options, bool enabled)
=> throw new NotImplementedException();

protected override string JsonSchemaPath
=> "src/Components/Aspire.Microsoft.Azure.Cosmos/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Microsoft.Data.SqlClient\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Microsoft.Data.SqlClient\Aspire.Microsoft.Data.SqlClient.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class ConformanceTests : ConformanceTests<SqlConnection, MicrosoftDataSql

protected override bool SupportsKeyedRegistrations => true;

protected override string JsonSchemaPath => "src/Components/Aspire.Microsoft.Data.SqlClient/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<ItemGroup>
<!-- this file is included as a link, as both components rely on different versions of EF (for now) -->
<Compile Include="..\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.Tests\TestDbContext.cs" Link="TestDbContext.cs" />

<None Include="$(RepoRoot)src\Components\Aspire.Microsoft.EntityFrameworkCore.Cosmos\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ protected override void SetTracing(EntityFrameworkCoreCosmosDBSettings options,
protected override void SetMetrics(EntityFrameworkCoreCosmosDBSettings options, bool enabled)
=> options.Metrics = enabled;

protected override string JsonSchemaPath
=> "src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<ItemGroup>
<!-- this file is included as a link, as both components rely on different versions of EF (for now) -->
<Compile Include="..\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.Tests\TestDbContext.cs" Link="TestDbContext.cs" />

<None Include="$(RepoRoot)src\Components\Aspire.Microsoft.EntityFrameworkCore.SqlServer\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class ConformanceTests_Pooling : ConformanceTests<TestDbContext, Microsof
"Microsoft.EntityFrameworkCore.Migrations"
};

protected override string JsonSchemaPath => "src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.MongoDB.Driver\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.MongoDB.Driver\Aspire.MongoDB.Driver.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.MongoDB.Driver.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class ConformanceTests : ConformanceTests<IMongoClient, MongoDBSettings>

protected override string ActivitySourceName => "MongoDB.Driver.Core.Extensions.DiagnosticSources";

protected override string JsonSchemaPath => "src/Components/Aspire.MongoDB.Driver/ConfigurationSchema.json";

protected override bool SupportsKeyedRegistrations => true;

protected override bool CanConnectToServer => s_canConnectToServer.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.MySqlConnector\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.MySqlConnector\Aspire.MySqlConnector.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.MySqlConnector.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class ConformanceTests : ConformanceTests<MySqlDataSource, MySqlConnector

protected override bool CanConnectToServer => s_canConnectToServer.Value;

protected override string JsonSchemaPath => "src/Components/Aspire.MySqlConnector/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class ConformanceTests_Pooling : ConformanceTests<TestDbContext, NpgsqlEn

protected override bool CanConnectToServer => s_canConnectToServer.Value;

protected override string JsonSchemaPath => "src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
2 changes: 2 additions & 0 deletions tests/Aspire.Npgsql.Tests/Aspire.Npgsql.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.Npgsql\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.Npgsql\Aspire.Npgsql.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.Npgsql.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class ConformanceTests : ConformanceTests<NpgsqlDataSource, NpgsqlSetting

protected override bool CanConnectToServer => s_canConnectToServer.Value;

protected override string JsonSchemaPath => "src/Components/Aspire.Npgsql/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<ItemGroup>
<!-- this file is included as a link, as both components rely on different versions of EF (for now) -->
<Compile Include="..\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.Tests\TestDbContext.cs" Link="TestDbContext.cs" />

<None Include="$(RepoRoot)src\Components\Aspire.Oracle.EntityFrameworkCore\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class ConformanceTests_Pooling : ConformanceTests<TestDbContext, OracleEn
"Microsoft.EntityFrameworkCore.Migrations"
};

protected override string JsonSchemaPath => "src/Components/Aspire.Oracle.EntityFrameworkCore/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="$(RepoRoot)src\Components\Aspire.RabbitMQ.Client\ConfigurationSchema.json" CopyToOutputDirectory="PreserveNewest" />

<ProjectReference Include="..\..\src\Components\Aspire.RabbitMQ.Client\Aspire.RabbitMQ.Client.csproj" />
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspire.RabbitMQ.Client.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class ConformanceTests : ConformanceTests<IConnection, RabbitMQClientSett

protected override string ActivitySourceName => "";

protected override string JsonSchemaPath => "src/Components/Aspire.RabbitMQ.Client/ConfigurationSchema.json";

protected override string ValidJsonConfig => """
{
"Aspire": {
Expand Down
Loading

0 comments on commit dff1467

Please sign in to comment.