From 301763fcefa1ac49b1a54eb5a04bdcaf7bbbc683 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 28 Apr 2020 14:02:00 -0400 Subject: [PATCH] More stuff --- tests/DMAPI/BasicOperation/Test.dm | 10 +- .../Instance/ChatTest.cs | 111 +++++++++++++++--- .../Instance/FunctionalTest.cs | 4 +- .../Instance/InstanceTest.cs | 4 +- 4 files changed, 102 insertions(+), 27 deletions(-) diff --git a/tests/DMAPI/BasicOperation/Test.dm b/tests/DMAPI/BasicOperation/Test.dm index aa49a038ca..d39bacedc3 100644 --- a/tests/DMAPI/BasicOperation/Test.dm +++ b/tests/DMAPI/BasicOperation/Test.dm @@ -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) diff --git a/tests/Tgstation.Server.Tests/Instance/ChatTest.cs b/tests/Tgstation.Server.Tests/Instance/ChatTest.cs index 825a5f1b6e..2e6a55fb89 100644 --- a/tests/Tgstation.Server.Tests/Instance/ChatTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/ChatTest.cs @@ -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 + { + 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(() => 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(() => chatClient.Update(updatedBot, cancellationToken), ErrorCode.ChatBotMaxChannels); + await ApiAssert.ThrowsException(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels); - var oldChannels = updatedBot.Channels; - updatedBot.Channels = null; - updatedBot.ChannelLimit = 0; - await ApiAssert.ThrowsException(() => chatClient.Update(updatedBot, cancellationToken), ErrorCode.ChatBotMaxChannels); + var oldChannels = discordBot.Channels; + discordBot.Channels = null; + discordBot.ChannelLimit = 0; + await ApiAssert.ThrowsException(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels); - updatedBot.Channels = oldChannels; - updatedBot.ChannelLimit = null; - await ApiAssert.ThrowsException(() => chatClient.Update(updatedBot, cancellationToken), ErrorCode.ChatBotMaxChannels); + discordBot.Channels = oldChannels; + discordBot.ChannelLimit = null; + await ApiAssert.ThrowsException(() => chatClient.Update(discordBot, cancellationToken), ErrorCode.ChatBotMaxChannels); var instance = metadata.CloneMetadata(); instance.ChatBotLimit = 0; await ApiAssert.ThrowsException(() => instanceClient.Update(instance, cancellationToken), ErrorCode.ChatBotMax); - - await chatClient.Delete(firstBot, cancellationToken); - bots = await chatClient.List(cancellationToken); - Assert.AreEqual(0, bots.Count); } } } diff --git a/tests/Tgstation.Server.Tests/Instance/FunctionalTest.cs b/tests/Tgstation.Server.Tests/Instance/FunctionalTest.cs index 13bdb71490..11128ad00d 100644 --- a/tests/Tgstation.Server.Tests/Instance/FunctionalTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/FunctionalTest.cs @@ -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; diff --git a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs index 1446e9a94c..1544c5c6c7 100644 --- a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs @@ -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; } } }