More stuff

This commit is contained in:
Jordan Brown
2020-04-28 14:02:00 -04:00
parent 7135b72c68
commit 301763fcef
4 changed files with 102 additions and 27 deletions
+5 -5
View File
@@ -1,10 +1,5 @@
/world/New()
TgsNew(minimum_required_security_level = TGS_SECURITY_SAFE)
// Validate TGS_DMAPI_VERSION against DMAPI version used
var/datum/tgs_version/active_version = world.TgsApiVersion()
var/datum/tgs_version/dmapi_version = new /datum/tgs_version(TGS_DMAPI_VERSION)
StartAsync()
/proc/StartAsync()
@@ -12,8 +7,13 @@
sleep(50)
world.TgsInitializationComplete()
sleep(50)
// Validate TGS_DMAPI_VERSION against DMAPI version used
var/datum/tgs_version/active_version = world.TgsApiVersion()
var/datum/tgs_version/dmapi_version = new /datum/tgs_version(TGS_DMAPI_VERSION)
if(!active_version.Equals(dmapi_version))
text2file("DMAPI version [TGS_DMAPI_VERSION] does not match active API version [active_version.raw_parameter]", "test_fail_reason.txt")
world.TgsEndProcess()
/world/Topic(T, Addr, Master, Keys)
@@ -23,7 +23,68 @@ namespace Tgstation.Server.Tests.Instance
this.metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
}
public async Task Run(CancellationToken cancellationToken)
public async Task RunPreWatchdog(CancellationToken cancellationToken)
{
var ircTask = RunIrc(cancellationToken);
await RunDiscord(cancellationToken);
await ircTask;
await RunLimitTests(cancellationToken);
}
async Task RunIrc(CancellationToken cancellationToken)
{
var firstBot = new ChatBot
{
ConnectionString = Environment.GetEnvironmentVariable("TGS4_TEST_IRC_CONNECTION_STRING"),
Enabled = false,
Name = "tgs4_integration_test",
Provider = ChatProvider.Irc,
ReconnectionInterval = 1,
ChannelLimit = 1
};
firstBot = await chatClient.Create(firstBot, cancellationToken);
Assert.AreNotEqual(0, firstBot.Id);
var bots = await chatClient.List(cancellationToken);
Assert.AreEqual(firstBot.Id, bots.First(x => x.Provider.Value == ChatProvider.Irc).Id);
var retrievedBot = await chatClient.GetId(firstBot, cancellationToken);
Assert.AreEqual(firstBot.Id, retrievedBot.Id);
firstBot.Enabled = true;
var updatedBot = await chatClient.Update(firstBot, cancellationToken);
Assert.AreEqual(true, updatedBot.Enabled);
var channelId = Environment.GetEnvironmentVariable("TGS4_TEST_IRC_CHANNEL");
firstBot.Channels = new List<ChatChannel>
{
new ChatChannel
{
IsAdminChannel = false,
IsUpdatesChannel = true,
IsWatchdogChannel = false,
Tag = "butt2",
IrcChannel = channelId
}
};
updatedBot = await chatClient.Update(firstBot, cancellationToken);
Assert.AreEqual(true, updatedBot.Enabled);
Assert.IsNotNull(updatedBot.Channels);
Assert.AreEqual(1, updatedBot.Channels.Count);
Assert.AreEqual(false, updatedBot.Channels.First().IsAdminChannel);
Assert.AreEqual(true, updatedBot.Channels.First().IsUpdatesChannel);
Assert.AreEqual(false, updatedBot.Channels.First().IsWatchdogChannel);
Assert.AreEqual("butt2", updatedBot.Channels.First().Tag);
Assert.AreEqual(channelId, updatedBot.Channels.First().IrcChannel);
Assert.IsNull(updatedBot.Channels.First().DiscordChannelId);
}
async Task RunDiscord(CancellationToken cancellationToken)
{
var firstBot = new ChatBot
{
@@ -40,8 +101,7 @@ namespace Tgstation.Server.Tests.Instance
Assert.AreNotEqual(0, firstBot.Id);
var bots = await chatClient.List(cancellationToken);
Assert.AreEqual(1, bots.Count);
Assert.AreEqual(firstBot.Id, bots.First().Id);
Assert.AreEqual(firstBot.Id, bots.First(x => x.Provider.Value == ChatProvider.Discord).Id);
var retrievedBot = await chatClient.GetId(firstBot, cancellationToken);
Assert.AreEqual(firstBot.Id, retrievedBot.Id);
@@ -63,7 +123,6 @@ namespace Tgstation.Server.Tests.Instance
DiscordChannelId = channelId
}
};
updatedBot = await chatClient.Update(firstBot, cancellationToken);
@@ -76,7 +135,22 @@ namespace Tgstation.Server.Tests.Instance
Assert.AreEqual("butt", updatedBot.Channels.First().Tag);
Assert.AreEqual(channelId, updatedBot.Channels.First().DiscordChannelId);
Assert.IsNull(updatedBot.Channels.First().IrcChannel);
}
public async Task RunPostWatchdog(CancellationToken cancellationToken)
{
var activeBots = await chatClient.List(cancellationToken);
Assert.AreEqual(2, activeBots.Count);
await Task.WhenAll(activeBots.Select(bot => chatClient.Delete(bot, cancellationToken)));
var nowBots = await chatClient.List(cancellationToken);
Assert.AreEqual(0, nowBots.Count);
}
async Task RunLimitTests(CancellationToken cancellationToken)
{
await ApiAssert.ThrowsException<ConflictException>(() => chatClient.Create(new ChatBot
{
Name = "asdf",
@@ -84,35 +158,34 @@ namespace Tgstation.Server.Tests.Instance
Provider = ChatProvider.Irc
}, cancellationToken), ErrorCode.ChatBotMax);
// We limited chat bots and channels to 1, try violating them
updatedBot.Channels.Add(
var bots = await chatClient.List(cancellationToken);
var discordBot = bots.First(bot => bot.Provider.Value == ChatProvider.Discord);
// We limited chat bots and channels to 1 and 2 respectively, try violating them
discordBot.Channels.Add(
new ChatChannel
{
IsAdminChannel = true,
IsUpdatesChannel = false,
IsWatchdogChannel = true,
Tag = "butt",
DiscordChannelId = channelId
DiscordChannelId = discordBot.Channels.First().DiscordChannelId
});
await ApiAssert.ThrowsException<ApiConflictException>(() => chatClient.Update(updatedBot, cancellationToken), ErrorCode.ChatBotMaxChannels);
await ApiAssert.ThrowsException<ApiConflictException>(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels);
var oldChannels = updatedBot.Channels;
updatedBot.Channels = null;
updatedBot.ChannelLimit = 0;
await ApiAssert.ThrowsException<ConflictException>(() => chatClient.Update(updatedBot, cancellationToken), ErrorCode.ChatBotMaxChannels);
var oldChannels = discordBot.Channels;
discordBot.Channels = null;
discordBot.ChannelLimit = 0;
await ApiAssert.ThrowsException<ConflictException>(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels);
updatedBot.Channels = oldChannels;
updatedBot.ChannelLimit = null;
await ApiAssert.ThrowsException<ConflictException>(() => chatClient.Update(updatedBot, cancellationToken), ErrorCode.ChatBotMaxChannels);
discordBot.Channels = oldChannels;
discordBot.ChannelLimit = null;
await ApiAssert.ThrowsException<ConflictException>(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels);
var instance = metadata.CloneMetadata();
instance.ChatBotLimit = 0;
await ApiAssert.ThrowsException<ConflictException>(() => instanceClient.Update(instance, cancellationToken), ErrorCode.ChatBotMax);
await chatClient.Delete(firstBot, cancellationToken);
bots = await chatClient.List(cancellationToken);
Assert.AreEqual(0, bots.Count);
}
}
}
@@ -28,7 +28,7 @@ namespace Tgstation.Server.Tests.Instance
{
await instanceClient.DreamMaker.Update(new DreamMaker
{
ApiValidationSecurityLevel = DreamDaemonSecurity.Trusted,
ApiValidationSecurityLevel = DreamDaemonSecurity.Ultrasafe,
ProjectName = "tests/DMAPI/BasicOperation/basic_operation_test"
}, cancellationToken);
@@ -73,7 +73,7 @@ namespace Tgstation.Server.Tests.Instance
async Task CheckDMApiFail(CompileJob compileJob, CancellationToken cancellationToken)
{
var failFile = Path.Combine(instanceClient.Metadata.Path, "Game", compileJob.DirectoryName.Value.ToString(), Path.GetDirectoryName(compileJob.DmeName), "test_fail_reason.txt");
var failFile = Path.Combine(instanceClient.Metadata.Path, "Game", compileJob.DirectoryName.Value.ToString(), "A", Path.GetDirectoryName(compileJob.DmeName), "test_fail_reason.txt");
if (!File.Exists(failFile))
return;
@@ -26,7 +26,7 @@ namespace Tgstation.Server.Tests.Instance
var repoTests = repoTest.RunPreWatchdog(cancellationToken);
var byondTests = byondTest.Run(cancellationToken);
var chatTests = chatTest.Run(cancellationToken);
var chatTests = chatTest.RunPreWatchdog(cancellationToken);
await configTest.Run(cancellationToken).ConfigureAwait(false);
await byondTests.ConfigureAwait(false);
await chatTests.ConfigureAwait(false);
@@ -34,7 +34,9 @@ namespace Tgstation.Server.Tests.Instance
await new FunctionalTest(instanceClient).Run(cancellationToken);
var chatShutdown = chatTest.RunPostWatchdog(cancellationToken);
await repoTest.RunPostWatchdog(cancellationToken);
await chatShutdown;
}
}
}