-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from GravityWolfNotAmused/dev
1.0.9.3 - Docker Fix & Test Cases
- Loading branch information
Showing
14 changed files
with
358 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Run Test Cases | ||
|
||
# Controls when the workflow will run | ||
on: | ||
pull_request: | ||
branches: [ "latest", "dev" ] | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
test: | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v2 | ||
with: | ||
dotnet-version: 6.0.x | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Test | ||
run: dotnet test --no-build --verbosity normal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
DiscordPlayerCountBot.Tests/DiscordPlayerCountBot.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DiscordPlayerCountBot\DiscordPlayerCountBot.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using DiscordPlayerCountBot.Tests.Environment; | ||
|
||
namespace DiscordPlayerCountBot.Tests; | ||
|
||
[Collection("Configuration Test Suite")] | ||
public class DockerConfigurationTests | ||
{ | ||
|
||
[Fact(DisplayName = "Test Docker Configuration with all data", Timeout = 30)] | ||
public async Task DockerConfigurationTestWithAllData() | ||
{ | ||
EnivronmentHelper.SetTestEnvironmentWithAllVariables(); | ||
|
||
var bots = new Dictionary<string, Bot>(); | ||
var time = -1; | ||
|
||
var dockerConfiguration = new DockerConfiguration(); | ||
var configuration = await dockerConfiguration.Configure(false); | ||
|
||
bots = configuration.Item1; | ||
time = configuration.Item2; | ||
|
||
EnivronmentHelper.ClearTestEnvironmentVariables(); | ||
|
||
Assert.True(time > 0, $"Time was returned from config and not zero. Actual: {time}"); | ||
Assert.True(bots.Count > 0, $"More than one bot was created. Actual: {bots.Count}"); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.Count >= 2, $"More than 2 tokens in the dictionary for the bot. Actual: {bots.ToList()[0].Value.ApplicationTokens.Count}"); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.ContainsKey("SteamAPIKey"), $"Steam Key should be present."); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.ContainsKey("BattleMetricsKey"), $"Battle Metrics Key should be present."); | ||
} | ||
|
||
[Fact(DisplayName = "Test Docker Configuration without Battle Metrics", Timeout = 30)] | ||
public async Task DockerConfigurationTestWithoutBattleMetrics() | ||
{ | ||
EnivronmentHelper.SetTestEnvironmentWithoutBattleMetrics(); | ||
|
||
var bots = new Dictionary<string, Bot>(); | ||
var time = -1; | ||
|
||
var dockerConfiguration = new DockerConfiguration(); | ||
var configuration = await dockerConfiguration.Configure(false); | ||
|
||
bots = configuration.Item1; | ||
time = configuration.Item2; | ||
|
||
EnivronmentHelper.ClearTestEnvironmentVariables(); | ||
|
||
Assert.True(time > 0, $"Time was returned from config and not zero. Actual: {time}"); | ||
Assert.True(bots.Count > 0, $"More than one bot was created. Actual: {bots.Count}"); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.Count == 1, $"1 token in the dictionary for the bots. Actual: {bots.ToList()[0].Value.ApplicationTokens.Count}"); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.ContainsKey("SteamAPIKey"), $"Steam Key should be present."); | ||
Assert.False(bots.ToList()[0].Value.ApplicationTokens.ContainsKey("BattleMetricsKey"), $"Battle Metrics Key should not be present."); | ||
} | ||
|
||
[Fact(DisplayName = "Test Docker Configuration without Application Variables", Timeout = 30)] | ||
public async Task DockerConfigurationTestWithoutApplicationVariables() | ||
{ | ||
EnivronmentHelper.SetTestEnvironmentWithoutApplicationVariables(); | ||
|
||
var bots = new Dictionary<string, Bot>(); | ||
var time = -1; | ||
|
||
var dockerConfiguration = new DockerConfiguration(); | ||
var configuration = await dockerConfiguration.Configure(false); | ||
|
||
bots = configuration.Item1; | ||
time = configuration.Item2; | ||
|
||
EnivronmentHelper.ClearTestEnvironmentVariables(); | ||
|
||
Assert.True(time > 0, $"Time was returned from config and not zero. Actual: {time}"); | ||
Assert.True(bots.Count > 0, $"More than one bot was created. Actual: {bots.Count}"); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.Count == 0, $"Should be 0 variables in the dictionary. Actual: {bots.ToList()[0].Value.ApplicationTokens.Count}"); | ||
} | ||
|
||
[Fact(DisplayName = "Test Docker Configuration without Steam variable", Timeout = 30)] | ||
public async Task DockerConfigurationTestWithoutSteam() | ||
{ | ||
EnivronmentHelper.SetTestEnvironmentWithoutSteam(); | ||
|
||
var bots = new Dictionary<string, Bot>(); | ||
var time = -1; | ||
|
||
var dockerConfiguration = new DockerConfiguration(); | ||
var configuration = await dockerConfiguration.Configure(false); | ||
|
||
bots = configuration.Item1; | ||
time = configuration.Item2; | ||
|
||
EnivronmentHelper.ClearTestEnvironmentVariables(); | ||
|
||
Assert.True(time > 0, $"Time was returned from config and not zero. Actual: {time}"); | ||
Assert.True(bots.Count > 0, $"More than one bot was created. Actual: {bots.Count}"); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.Count == 1, $"1 token in the dictionary for the bots. Actual: {bots.ToList()[0].Value.ApplicationTokens.Count}"); | ||
Assert.True(bots.ToList()[0].Value.ApplicationTokens.ContainsKey("BattleMetricsKey"), $"Battle Metrics Key should be present."); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
DiscordPlayerCountBot.Tests/Environment/EnivronmentHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace DiscordPlayerCountBot.Tests.Environment | ||
{ | ||
public static class EnivronmentHelper | ||
{ | ||
public static void SetTestEnvironmentWithAllVariables() | ||
{ | ||
System.Environment.SetEnvironmentVariable("ISDOCKER", "true"); | ||
System.Environment.SetEnvironmentVariable("BOT_NAMES", "Steam;CFX;Scum;Minecraft;BattleMetrics"); | ||
System.Environment.SetEnvironmentVariable("BOT_PUBADDRESSES", "51.222.191.212;96.43.133.194;178.63.74.20;minecraft.hypixel.net;15086629"); | ||
System.Environment.SetEnvironmentVariable("BOT_PORTS", "2403;30120;7042;25565;0"); | ||
System.Environment.SetEnvironmentVariable("BOT_DISCORD_TOKENS", "1;2;3;4;5"); | ||
System.Environment.SetEnvironmentVariable("BOT_USERNAMETAGS", "false;false;false;false;false"); | ||
System.Environment.SetEnvironmentVariable("BOT_STATUSES", "Steam;CFX;Scum;Minecraft;BattleMetrics"); | ||
System.Environment.SetEnvironmentVariable("BOT_PROVIDERTYPES", "3;3;3;3;3"); | ||
System.Environment.SetEnvironmentVariable("BOT_UPDATE_TIME", "10"); | ||
System.Environment.SetEnvironmentVariable("BOT_APPLICATION_VARIABLES", "SteamAPIKey,12345;BattleMetricsKey,12345"); | ||
} | ||
public static void SetTestEnvironmentWithoutSteam() | ||
{ | ||
System.Environment.SetEnvironmentVariable("ISDOCKER", "true"); | ||
System.Environment.SetEnvironmentVariable("BOT_NAMES", "CFX;Scum;Minecraft;BattleMetrics"); | ||
System.Environment.SetEnvironmentVariable("BOT_PUBADDRESSES", "96.43.133.194;178.63.74.20;minecraft.hypixel.net;15086629"); | ||
System.Environment.SetEnvironmentVariable("BOT_PORTS", "30120;7042;25565;0"); | ||
System.Environment.SetEnvironmentVariable("BOT_DISCORD_TOKENS", "2;3;4;5"); | ||
System.Environment.SetEnvironmentVariable("BOT_USERNAMETAGS", "false;false;false;false"); | ||
System.Environment.SetEnvironmentVariable("BOT_STATUSES", "CFX;Scum;Minecraft;BattleMetrics"); | ||
System.Environment.SetEnvironmentVariable("BOT_PROVIDERTYPES", "3;3;3;3"); | ||
System.Environment.SetEnvironmentVariable("BOT_UPDATE_TIME", "10"); | ||
System.Environment.SetEnvironmentVariable("BOT_APPLICATION_VARIABLES", "BattleMetricsKey,12345"); | ||
} | ||
|
||
public static void SetTestEnvironmentWithoutBattleMetrics() | ||
{ | ||
System.Environment.SetEnvironmentVariable("ISDOCKER", "true"); | ||
System.Environment.SetEnvironmentVariable("BOT_NAMES", "Steam;CFX;Scum;Minecraft"); | ||
System.Environment.SetEnvironmentVariable("BOT_PUBADDRESSES", "51.222.191.212;96.43.133.194;178.63.74.20;minecraft.hypixel.net"); | ||
System.Environment.SetEnvironmentVariable("BOT_PORTS", "2403;30120;7042;25565"); | ||
System.Environment.SetEnvironmentVariable("BOT_DISCORD_TOKENS", "1;2;3;4"); | ||
System.Environment.SetEnvironmentVariable("BOT_USERNAMETAGS", "false;false;false;false"); | ||
System.Environment.SetEnvironmentVariable("BOT_STATUSES", "Steam;CFX;Scum;Minecraft"); | ||
System.Environment.SetEnvironmentVariable("BOT_PROVIDERTYPES", "3;3;3;3"); | ||
System.Environment.SetEnvironmentVariable("BOT_UPDATE_TIME", "10"); | ||
System.Environment.SetEnvironmentVariable("BOT_APPLICATION_VARIABLES", "SteamAPIKey,12345"); | ||
} | ||
|
||
public static void SetTestEnvironmentWithoutApplicationVariables() | ||
{ | ||
System.Environment.SetEnvironmentVariable("ISDOCKER", "true"); | ||
System.Environment.SetEnvironmentVariable("BOT_NAMES", "Steam;CFX;Scum;Minecraft;BattleMetrics"); | ||
System.Environment.SetEnvironmentVariable("BOT_PUBADDRESSES", "51.222.191.212;96.43.133.194;178.63.74.20;minecraft.hypixel.net;15086629"); | ||
System.Environment.SetEnvironmentVariable("BOT_PORTS", "2403;30120;7042;25565;0"); | ||
System.Environment.SetEnvironmentVariable("BOT_DISCORD_TOKENS", "1;2;3;4;5"); | ||
System.Environment.SetEnvironmentVariable("BOT_USERNAMETAGS", "false;false;false;false;false"); | ||
System.Environment.SetEnvironmentVariable("BOT_STATUSES", "Steam;CFX;Scum;Minecraft;BattleMetrics"); | ||
System.Environment.SetEnvironmentVariable("BOT_PROVIDERTYPES", "3;3;3;3;3"); | ||
System.Environment.SetEnvironmentVariable("BOT_UPDATE_TIME", "10"); | ||
} | ||
|
||
public static void ClearTestEnvironmentVariables() | ||
{ | ||
System.Environment.SetEnvironmentVariable("ISDOCKER", null); | ||
System.Environment.SetEnvironmentVariable("BOT_NAMES", null); | ||
System.Environment.SetEnvironmentVariable("BOT_PUBADDRESSES", null); | ||
System.Environment.SetEnvironmentVariable("BOT_PORTS", null); | ||
System.Environment.SetEnvironmentVariable("BOT_DISCORD_TOKENS", null); | ||
System.Environment.SetEnvironmentVariable("BOT_USERNAMETAGS", null); | ||
System.Environment.SetEnvironmentVariable("BOT_STATUSES", null); | ||
System.Environment.SetEnvironmentVariable("BOT_PROVIDERTYPES", null); | ||
System.Environment.SetEnvironmentVariable("BOT_UPDATE_TIME", null); | ||
System.Environment.SetEnvironmentVariable("BOT_APPLICATION_VARIABLES", null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
global using Xunit; | ||
global using DiscordPlayerCountBot.Configuration; | ||
global using PlayerCountBot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.