Skip to content

Commit

Permalink
INTEGRATE MY TESTS
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeViper committed Jan 15, 2025
1 parent 4ffcf42 commit 6633895
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Config/ConfigLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,46 @@ public static void LoadConfigs()
{
NodeConfig.Instance.ApplyKubeHostname(nodeName);
}

LoadTestDbConfig();

var testRedis = Environment.GetEnvironmentVariable("TEST_REDIS");
if (testRedis is not null)
{
RedisConfig.Current.ConnectionString = testRedis;
Console.WriteLine($"Using test redis: {testRedis}");
}
}

public static void LoadTestDbConfig()
{
// Check for integration test database details
var testDb = Environment.GetEnvironmentVariable("TEST_DB");
if (testDb is not null)
{
DbConfig.Instance.Database = testDb;
Console.WriteLine($"Using test database: {testDb}");
}

var testDbUser = Environment.GetEnvironmentVariable("TEST_DB_USER");
if (testDbUser is not null)
{
DbConfig.Instance.Username = testDbUser;
Console.WriteLine($"Using test database user: {testDbUser}");
}

var testDbPass = Environment.GetEnvironmentVariable("TEST_DB_PASS");
if (testDbPass is not null)
{
DbConfig.Instance.Password = testDbPass;
Console.WriteLine("Using test database password");
}

var testDbHost = Environment.GetEnvironmentVariable("TEST_DB_HOST");
if (testDbHost is not null)
{
DbConfig.Instance.Host = testDbHost;
Console.WriteLine($"Using test database host: {testDbHost}");
}
}
}
2 changes: 1 addition & 1 deletion Valour/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Valour.Server;

public class Program
public partial class Program
{
public static List<object> DynamicApis { get; set; }

Expand Down
4 changes: 4 additions & 0 deletions Valour/Server/Valour.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<DebugType>embedded</DebugType>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="..\Tests\Valour.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="4.0.0-preview.3" />
<PackageReference Include="ExCSS" Version="4.3.0" />
Expand Down
25 changes: 25 additions & 0 deletions Valour/Tests/Apis/UserApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Valour.Server;

namespace Valour.Tests.Apis;

public class UserApiTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly HttpClient _client;

public UserApiTests(WebApplicationFactory<Program> fixture)
{
_client = fixture.CreateClient();
}

[Fact]
public async Task TestGetUserCount()
{
var response = await _client.GetAsync("api/users/count");
response.EnsureSuccessStatusCode();

// Ensure response is a number
var content = await response.Content.ReadAsStringAsync();
Assert.True(int.TryParse(content, out _));
}
}
1 change: 1 addition & 0 deletions Valour/Tests/Valour.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.1" />
<PackageReference Include="coverlet.collector" Version="6.0.3"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
Expand Down

0 comments on commit 6633895

Please sign in to comment.