mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2024-09-19 12:18:48 -04:00
Use local secret store for tests instead of hand-made solution
This commit is contained in:
parent
bf76f10030
commit
fc29735a45
4 changed files with 17 additions and 26 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -21,6 +21,3 @@ bld/
|
||||||
|
|
||||||
# Coverage
|
# Coverage
|
||||||
*.opencover.xml
|
*.opencover.xml
|
||||||
|
|
||||||
# Secrets
|
|
||||||
*.secret
|
|
|
@ -1,8 +1,9 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>true</IsTestProject>
|
<IsTestProject>true</IsTestProject>
|
||||||
|
<UserSecretsId>d1fe5ae2-2a19-404d-a36e-81ba9eada1c1</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -15,6 +16,9 @@
|
||||||
<PackageReference Include="FluentAssertions" Version="6.9.0" />
|
<PackageReference Include="FluentAssertions" Version="6.9.0" />
|
||||||
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" PrivateAssets="all" />
|
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" PrivateAssets="all" />
|
||||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
|
||||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.2" />
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
|
|
@ -1,26 +1,17 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.Reflection;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Tests.Infra;
|
namespace DiscordChatExporter.Cli.Tests.Infra;
|
||||||
|
|
||||||
internal static class Secrets
|
internal static class Secrets
|
||||||
{
|
{
|
||||||
private static readonly Lazy<string> DiscordTokenLazy = new(() =>
|
private static readonly IConfigurationRoot Configuration = new ConfigurationBuilder()
|
||||||
{
|
.AddUserSecrets(Assembly.GetExecutingAssembly())
|
||||||
var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
|
.AddEnvironmentVariables()
|
||||||
if (!string.IsNullOrWhiteSpace(fromEnvironment))
|
.Build();
|
||||||
return fromEnvironment;
|
|
||||||
|
|
||||||
var secretFilePath = Path.Combine(
|
|
||||||
Path.GetDirectoryName(typeof(Secrets).Assembly.Location) ?? Directory.GetCurrentDirectory(),
|
|
||||||
"DiscordToken.secret"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (File.Exists(secretFilePath))
|
|
||||||
return File.ReadAllText(secretFilePath);
|
|
||||||
|
|
||||||
|
public static string DiscordToken =>
|
||||||
|
Configuration["DISCORD_TOKEN"] ??
|
||||||
throw new InvalidOperationException("Discord token not provided for tests.");
|
throw new InvalidOperationException("Discord token not provided for tests.");
|
||||||
});
|
|
||||||
|
|
||||||
public static string DiscordToken => DiscordTokenLazy.Value;
|
|
||||||
}
|
}
|
|
@ -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)
|
1. [Join the test server](https://discord.gg/eRV8Vap5bm)
|
||||||
2. Locate your Discord authentication token
|
2. Locate your Discord authentication token
|
||||||
3. Specify your token using a file or an environment variable:
|
3. Add your token to user secrets: `dotnet user-secrets set DISCORD_TOKEN <token>`
|
||||||
- **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`
|
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
|
> **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.
|
Loading…
Reference in a new issue