diff --git a/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs b/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs index 88938d99..ba6c7889 100644 --- a/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs +++ b/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs @@ -24,12 +24,19 @@ namespace DiscordChatExporter.Cli.Tests.Infra private static readonly Lazy IsDiscordTokenBotLazy = new(() => { - // Default to true var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN_BOT"); - if (string.IsNullOrWhiteSpace(fromEnvironment)) + if (!string.IsNullOrWhiteSpace(fromEnvironment)) + return string.Equals(fromEnvironment, "true", StringComparison.OrdinalIgnoreCase); + + var secretFilePath = Path.Combine( + Path.GetDirectoryName(typeof(Secrets).Assembly.Location) ?? Directory.GetCurrentDirectory(), + "DiscordTokenBot.secret" + ); + + if (File.Exists(secretFilePath)) return true; - return string.Equals(fromEnvironment, "true", StringComparison.OrdinalIgnoreCase); + return false; }); public static string DiscordToken => DiscordTokenLazy.Value; diff --git a/DiscordChatExporter.Cli.Tests/Readme.md b/DiscordChatExporter.Cli.Tests/Readme.md new file mode 100644 index 00000000..acc50135 --- /dev/null +++ b/DiscordChatExporter.Cli.Tests/Readme.md @@ -0,0 +1,17 @@ +# DiscordChatExporter Tests + +This test suite runs against a real Discord server, specifically created to exercise different behaviors required by the test scenarios. +In order to run these tests locally, you need to join the test server and configure your authentication token. + +1. Join the 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 +4. Run the tests: `dotnet test` + +> 🟣 If you're submitting a pull request, you don't _have_ to run the tests locally -- they are executed automatically by CI. +Running them locally can still sometimes be useful for debugging purposes though. + +> 🟣 If you want to have a new test case or a scenario added, please let me know in your pull request. +Currently, it's not possible to add them by yourself. \ No newline at end of file