You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DiscordChatExporter/DiscordChatExporter.Cli.Tests/Infra/Secrets.cs

26 lines
818 B

using System;
using System.IO;
3 years ago
namespace DiscordChatExporter.Cli.Tests.Infra;
internal static class Secrets
{
3 years ago
private static readonly Lazy<string> DiscordTokenLazy = new(() =>
{
3 years ago
var fromEnvironment = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
if (!string.IsNullOrWhiteSpace(fromEnvironment))
return fromEnvironment;
3 years ago
var secretFilePath = Path.Combine(
Path.GetDirectoryName(typeof(Secrets).Assembly.Location) ?? Directory.GetCurrentDirectory(),
"DiscordToken.secret"
);
3 years ago
if (File.Exists(secretFilePath))
return File.ReadAllText(secretFilePath);
3 years ago
throw new InvalidOperationException("Discord token not provided for tests.");
});
3 years ago
public static string DiscordToken => DiscordTokenLazy.Value;
}