<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host;

namespace Tgstation.Server.Tests
{
	sealed class TestingServer : IServer
	{
		public Uri Url { get; }

		public string Directory { get; }
		public bool RestartRequested => realServer.RestartRequested;

		readonly IServer realServer;

		public TestingServer()
		{
			Directory = Path.GetTempFileName();
			File.Delete(Directory);
			System.IO.Directory.CreateDirectory(Directory);
			Url = new Uri("http://localhost:5001");

			//so we need a db
			//we have to rely on env vars
			var databaseType = Environment.GetEnvironmentVariable("TGS4_TEST_DATABASE_TYPE");
			var connectionString = Environment.GetEnvironmentVariable("TGS4_TEST_CONNECTION_STRING");

			if (String.IsNullOrEmpty(databaseType))
				Assert.Fail("No database type configured in env var TGS4_TEST_DATABASE_TYPE!");

			if (String.IsNullOrEmpty(connectionString))
				Assert.Fail("No connection string configured in env var TGS4_TEST_CONNECTION_STRING!");

			realServer = new ServerFactory().CreateServer(new string[]
			{
				"--urls",
				Url.ToString(),
				String.Format(CultureInfo.InvariantCulture, "Database:DatabaseType={0}", databaseType),
				String.Format(CultureInfo.InvariantCulture, "Database:ConnectionString={0}", connectionString),
				"Database:DropDatabase=true"
			}, null);
		}

		public void Dispose()
		{
			realServer.Dispose();
			System.IO.Directory.Delete(Directory, true);
		}

		public Task RunAsync(CancellationToken cancellationToken) => realServer.RunAsync(cancellationToken);
	}
}<commit_msg>Add GitHubAccessToken support to the tests<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host;

namespace Tgstation.Server.Tests
{
	sealed class TestingServer : IServer
	{
		public Uri Url { get; }

		public string Directory { get; }
		public bool RestartRequested => realServer.RestartRequested;

		readonly IServer realServer;

		public TestingServer()
		{
			Directory = Path.GetTempFileName();
			File.Delete(Directory);
			System.IO.Directory.CreateDirectory(Directory);
			Url = new Uri("http://localhost:5001");

			//so we need a db
			//we have to rely on env vars
			var databaseType = Environment.GetEnvironmentVariable("TGS4_TEST_DATABASE_TYPE");
			var connectionString = Environment.GetEnvironmentVariable("TGS4_TEST_CONNECTION_STRING");
			var gitHubAccessToken = Environment.GetEnvironmentVariable("TGS4_TEST_GITHUB_TOKEN");

			if (String.IsNullOrEmpty(databaseType))
				Assert.Fail("No database type configured in env var TGS4_TEST_DATABASE_TYPE!");

			if (String.IsNullOrEmpty(connectionString))
				Assert.Fail("No connection string configured in env var TGS4_TEST_CONNECTION_STRING!");

			var args = new List<string>()
			{
				"--urls",
				Url.ToString(),
				String.Format(CultureInfo.InvariantCulture, "Database:DatabaseType={0}", databaseType),
				String.Format(CultureInfo.InvariantCulture, "Database:ConnectionString={0}", connectionString),
				"Database:DropDatabase=true"
			};

			if (!String.IsNullOrEmpty(gitHubAccessToken))
				args.Add(String.Format(CultureInfo.InvariantCulture, "General:GitHubAccessToken={0}", gitHubAccessToken));

			realServer = new ServerFactory().CreateServer(args.ToArray(), null);
		}

		public void Dispose()
		{
			realServer.Dispose();
			System.IO.Directory.Delete(Directory, true);
		}

		public Task RunAsync(CancellationToken cancellationToken) => realServer.RunAsync(cancellationToken);
	}
}
{'fraction_non_alphanumeric': 0.10824468085106383, 'fraction_numerical': 0.005851063829787234, 'mean_word_length': 5.24750830564784, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '969213', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1079, 'n_words': 232}