diff --git a/.gitignore b/.gitignore index 33e5fdf..ae785f7 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,4 @@ bld/ [Oo]bj/ # Coverage -*.opencover.xml - -# Secrets -*.secret \ No newline at end of file +*.opencover.xml \ No newline at end of file diff --git a/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj b/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj index 26f7c13..3e8b7a5 100644 --- a/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj +++ b/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj @@ -1,8 +1,9 @@ - + false true + d1fe5ae2-2a19-404d-a36e-81ba9eada1c1 @@ -15,6 +16,9 @@ + + + diff --git a/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs b/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs index 5d3180d..935477f 100644 --- a/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs +++ b/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs @@ -1,26 +1,17 @@ using System; -using System.IO; +using System.Reflection; +using Microsoft.Extensions.Configuration; namespace DiscordChatExporter.Cli.Tests.Infra; internal static class Secrets { - private static readonly Lazy DiscordTokenLazy = new(() => - { - var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN"); - if (!string.IsNullOrWhiteSpace(fromEnvironment)) - return fromEnvironment; - - var secretFilePath = Path.Combine( - Path.GetDirectoryName(typeof(Secrets).Assembly.Location) ?? Directory.GetCurrentDirectory(), - "DiscordToken.secret" - ); - - if (File.Exists(secretFilePath)) - return File.ReadAllText(secretFilePath); + private static readonly IConfigurationRoot Configuration = new ConfigurationBuilder() + .AddUserSecrets(Assembly.GetExecutingAssembly()) + .AddEnvironmentVariables() + .Build(); + public static string DiscordToken => + Configuration["DISCORD_TOKEN"] ?? throw new InvalidOperationException("Discord token not provided for tests."); - }); - - public static string DiscordToken => DiscordTokenLazy.Value; } \ No newline at end of file diff --git a/DiscordChatExporter.Cli.Tests/Readme.md b/DiscordChatExporter.Cli.Tests/Readme.md index e175e97..359d299 100644 --- a/DiscordChatExporter.Cli.Tests/Readme.md +++ b/DiscordChatExporter.Cli.Tests/Readme.md @@ -5,9 +5,8 @@ In order to run these tests locally, you need to join the test server and config 1. [Join the test server](https://discord.gg/eRV8Vap5bm) 2. Locate your Discord authentication token -3. Specify your token using a file or an environment variable: - - **Using a file**: put your token in a new `DiscordToken.secret` file created in this directory - - **Using an environment variable**: set `DISCORD_TOKEN` variable to your token +3. Add your token to user secrets: `dotnet user-secrets set DISCORD_TOKEN ` 4. Run the tests: `dotnet test` -> If you want to add a new test case, please let me know and I will give you the required permissions \ No newline at end of file +> **Note**: +> If you want to add a new test case, please let me know and I will give you the required permissions on the server. \ No newline at end of file