From 7c5f6c07f21878a67cebb138848f7b4b4f4a831c Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 23 Apr 2020 18:21:30 -0400 Subject: [PATCH] Working on integration tests --- .travis.yml | 2 +- .../Components/Repository/Repository.cs | 31 ++- .../Controllers/JobController.cs | 4 +- .../Controllers/RepositoryController.cs | 6 +- src/Tgstation.Server.Host/Jobs/JobManager.cs | 7 +- tests/DMAPI/{ => BasicOperation}/Config.dm | 4 +- tests/DMAPI/{ => BasicOperation}/Test.dm | 5 + .../basic_operation_test.dme} | 3 +- .../DMAPI/{ => BasicOperation}/build_byond.sh | 0 tests/DMAPI/tgs_include.dm | 2 + .../Instance/ByondTest.cs | 36 ++- .../Instance/InstanceTest.cs | 5 + .../Instance/JobsRequiredTest.cs | 68 ++++++ .../Instance/RepositoryTest.cs | 207 ++++++++++++++++++ 14 files changed, 342 insertions(+), 38 deletions(-) rename tests/DMAPI/{ => BasicOperation}/Config.dm (84%) rename tests/DMAPI/{ => BasicOperation}/Test.dm (90%) rename tests/DMAPI/{travistester.dme => BasicOperation/basic_operation_test.dme} (77%) rename tests/DMAPI/{ => BasicOperation}/build_byond.sh (100%) mode change 100755 => 100644 create mode 100644 tests/DMAPI/tgs_include.dm create mode 100644 tests/Tgstation.Server.Tests/Instance/JobsRequiredTest.cs create mode 100644 tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs diff --git a/.travis.yml b/.travis.yml index 012a2b2469..c6db7c10f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,6 +63,6 @@ install: - if [ $DockerBuild = false ] && [ $DMAPI = false ]; then dotnet restore tgstation-server.sln; fi script: - - if [ $DockerBuild = false ] && [ $DMAPI = true ]; then tests/DMAPI/build_byond.sh || travis_terminate 1; fi + - if [ $DockerBuild = false ] && [ $DMAPI = true ]; then tests/DMAPI/BasicOperation/build_byond.sh || travis_terminate 1; fi - if [ $DockerBuild = false ] && [ $DMAPI = false ]; then build/test_core.sh; fi - if [ $DockerBuild = true ]; then docker build . -f build/Dockerfile; fi diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index 961a7910b8..1ea8f8abd8 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -191,11 +191,34 @@ namespace Tgstation.Server.Host.Components.Repository progressReporter(0); cancellationToken.ThrowIfCancellationRequested(); - Commands.Checkout(repository, committish, new CheckoutOptions + void RunCheckout() => + Commands.Checkout(repository, committish, new CheckoutOptions + { + CheckoutModifiers = CheckoutModifiers.Force, + OnCheckoutProgress = CheckoutProgressHandler(progressReporter) + }); + + try { - CheckoutModifiers = CheckoutModifiers.Force, - OnCheckoutProgress = CheckoutProgressHandler(progressReporter) - }); + RunCheckout(); + } + catch (NotFoundException) + { + // Maybe (likely) a remote? + var remoteName = $"origin/{committish}"; + var potentialBranch = repository.Branches.FirstOrDefault( + branch => branch.FriendlyName.Equals(remoteName, StringComparison.Ordinal)); + cancellationToken.ThrowIfCancellationRequested(); + + if (potentialBranch == default) + throw; + + logger.LogDebug("Creating local branch for {0}...", potentialBranch.FriendlyName); + repository.CreateBranch(committish, potentialBranch.Tip); + cancellationToken.ThrowIfCancellationRequested(); + + RunCheckout(); + } cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Tgstation.Server.Host/Controllers/JobController.cs b/src/Tgstation.Server.Host/Controllers/JobController.cs index 1b5af85311..f912483f85 100644 --- a/src/Tgstation.Server.Host/Controllers/JobController.cs +++ b/src/Tgstation.Server.Host/Controllers/JobController.cs @@ -99,8 +99,8 @@ namespace Tgstation.Server.Host.Controllers if (job.CancelRight.HasValue && job.CancelRightsType.HasValue && (AuthenticationContext.GetRight(job.CancelRightsType.Value) & job.CancelRight.Value) == 0) return Forbid(); - job = await jobManager.CancelJob(job, AuthenticationContext.User, false, cancellationToken).ConfigureAwait(false); - return job != null ? (IActionResult)Accepted(job.ToApi()) : StatusCode((int)HttpStatusCode.Gone); + var updatedJob = await jobManager.CancelJob(job, AuthenticationContext.User, false, cancellationToken).ConfigureAwait(false); + return updatedJob != null ? (IActionResult)Accepted(updatedJob.ToApi()) : StatusCode((int)HttpStatusCode.Gone); } /// diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index f2006ed345..fb505b268c 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -326,9 +326,6 @@ namespace Tgstation.Server.Host.Controllers if (model.CheckoutSha != null && model.UpdateFromOrigin == true) return BadRequest(new ErrorMessage(ErrorCode.RepoMismatchShaAndUpdate)); - if (model.Origin != null) - return BadRequest(new ErrorMessage(ErrorCode.RepoCantChangeOrigin)); - if (model.NewTestMerges?.Any(x => model.NewTestMerges.Any(y => x != y && x.Number == y.Number)) == true) return BadRequest(new ErrorMessage(ErrorCode.RepoDuplicateTestMerge)); @@ -404,6 +401,9 @@ namespace Tgstation.Server.Host.Controllers if (repo == null) return Conflict(new ErrorMessage(ErrorCode.RepoMissing)); await PopulateApi(api, repo, DatabaseContext, Instance, cancellationToken).ConfigureAwait(false); + + if (model.Origin != null && model.Origin != repo.Origin) + return BadRequest(new ErrorMessage(ErrorCode.RepoCantChangeOrigin)); } } diff --git a/src/Tgstation.Server.Host/Jobs/JobManager.cs b/src/Tgstation.Server.Host/Jobs/JobManager.cs index 677cb36238..0a458419a0 100644 --- a/src/Tgstation.Server.Host/Jobs/JobManager.cs +++ b/src/Tgstation.Server.Host/Jobs/JobManager.cs @@ -238,14 +238,15 @@ namespace Tgstation.Server.Host.Jobs handler.Cancel(); // this will ensure the db update is only done once await databaseContextFactory.UseContext(async databaseContext => { - job = new Job { Id = job.Id }; + var updatedJob = new Job { Id = job.Id }; databaseContext.Jobs.Attach(job); - user = new User { Id = user.Id }; + var attachedUser = new User { Id = user.Id }; databaseContext.Users.Attach(user); - job.CancelledBy = user; + updatedJob.CancelledBy = attachedUser; // let either startup or cancellation set job.cancelled await databaseContext.Save(cancellationToken).ConfigureAwait(false); + job.CancelledBy = user; }).ConfigureAwait(false); if (blocking) await handler.Wait(cancellationToken).ConfigureAwait(false); diff --git a/tests/DMAPI/Config.dm b/tests/DMAPI/BasicOperation/Config.dm similarity index 84% rename from tests/DMAPI/Config.dm rename to tests/DMAPI/BasicOperation/Config.dm index fc466e2b61..1fff7f2a61 100644 --- a/tests/DMAPI/Config.dm +++ b/tests/DMAPI/BasicOperation/Config.dm @@ -7,5 +7,5 @@ #define TGS_INFO_LOG(message) world.log << "Info: [##message]" #define TGS_WARNING_LOG(message) world.log << "Warn: [##message]" #define TGS_ERROR_LOG(message) world.log << "Err: [##message]" -#define TGS_NOTIFY_ADMINS(event) message_admins(event) -#define TGS_CLIENT_COUNT clients.len +#define TGS_NOTIFY_ADMINS(event) +#define TGS_CLIENT_COUNT 0 diff --git a/tests/DMAPI/Test.dm b/tests/DMAPI/BasicOperation/Test.dm similarity index 90% rename from tests/DMAPI/Test.dm rename to tests/DMAPI/BasicOperation/Test.dm index cefcbe33ff..8b7ecd6253 100644 --- a/tests/DMAPI/Test.dm +++ b/tests/DMAPI/BasicOperation/Test.dm @@ -1,5 +1,10 @@ /world/New() TgsNew() + StartAsync() + +/proc/StartAsync() + set waitfor = FALSE + sleep(100) TgsInitializationComplete() /world/Topic(T, Addr, Master, Keys) diff --git a/tests/DMAPI/travistester.dme b/tests/DMAPI/BasicOperation/basic_operation_test.dme similarity index 77% rename from tests/DMAPI/travistester.dme rename to tests/DMAPI/BasicOperation/basic_operation_test.dme index c3b64fc12b..92781c7e16 100644 --- a/tests/DMAPI/travistester.dme +++ b/tests/DMAPI/BasicOperation/basic_operation_test.dme @@ -12,7 +12,6 @@ // BEGIN_INCLUDE #include "Config.dm" -#include "..\..\src\DMAPI\tgs.dm" -#include "..\..\src\DMAPI\tgs\includes.dm" +#include "..\tgs_include.dm" #include "Test.dm" // END_INCLUDE diff --git a/tests/DMAPI/build_byond.sh b/tests/DMAPI/BasicOperation/build_byond.sh old mode 100755 new mode 100644 similarity index 100% rename from tests/DMAPI/build_byond.sh rename to tests/DMAPI/BasicOperation/build_byond.sh diff --git a/tests/DMAPI/tgs_include.dm b/tests/DMAPI/tgs_include.dm new file mode 100644 index 0000000000..d60b655b94 --- /dev/null +++ b/tests/DMAPI/tgs_include.dm @@ -0,0 +1,2 @@ +#include "..\..\src\DMAPI\tgs.dm" +#include "..\..\src\DMAPI\tgs\includes.dm" diff --git a/tests/Tgstation.Server.Tests/Instance/ByondTest.cs b/tests/Tgstation.Server.Tests/Instance/ByondTest.cs index 248a7c4f79..93a6fb1f20 100644 --- a/tests/Tgstation.Server.Tests/Instance/ByondTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/ByondTest.cs @@ -6,21 +6,32 @@ using Tgstation.Server.Client.Components; namespace Tgstation.Server.Tests.Instance { - sealed class ByondTest + sealed class ByondTest : JobsRequiredTest { readonly IByondClient byondClient; - readonly IJobsClient jobsClient; public ByondTest(IByondClient byondClient, IJobsClient jobsClient) + : base(jobsClient) { this.byondClient = byondClient ?? throw new ArgumentNullException(nameof(byondClient)); - this.jobsClient = jobsClient ?? throw new ArgumentNullException(nameof(jobsClient)); } public async Task Run(CancellationToken cancellationToken) { await TestNoVersion(cancellationToken).ConfigureAwait(false); await TestInstall511(cancellationToken).ConfigureAwait(false); + await TestInstallFakeVersion(cancellationToken).ConfigureAwait(false); + } + + async Task TestInstallFakeVersion(CancellationToken cancellationToken) + { + var newModel = new Api.Models.Byond + { + Version = new Version(5011, 1385) + }; + var test = await byondClient.SetActiveVersion(newModel, cancellationToken).ConfigureAwait(false); + Assert.IsNotNull(test.InstallJob); + await WaitForJob(test.InstallJob, 60, true, cancellationToken).ConfigureAwait(false); } async Task TestInstall511(CancellationToken cancellationToken) @@ -32,24 +43,7 @@ namespace Tgstation.Server.Tests.Instance var test = await byondClient.SetActiveVersion(newModel, cancellationToken).ConfigureAwait(false); Assert.IsNotNull(test.InstallJob); Assert.IsNull(test.Version); - var job = test.InstallJob; - var maxWait = 60; //it's 10MB max give me a break - do - { - await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); - job = await jobsClient.GetId(job, cancellationToken).ConfigureAwait(false); - --maxWait; - } - while (!job.StoppedAt.HasValue && maxWait > 0); - if (!job.StoppedAt.HasValue) - { - await jobsClient.Cancel(job, cancellationToken).ConfigureAwait(false); - Assert.Fail("Byond installation job timed out!"); - } - - if (job.ExceptionDetails != null) - Assert.Fail(job.ExceptionDetails); - + var job = await WaitForJob(test.InstallJob, 60, false, cancellationToken).ConfigureAwait(false); var currentShit = await byondClient.ActiveVersion(cancellationToken).ConfigureAwait(false); Assert.AreEqual(newModel.Version, currentShit.Version); } diff --git a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs index b83c8be9c4..dc670f209d 100644 --- a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs @@ -22,12 +22,17 @@ namespace Tgstation.Server.Tests.Instance var byondTest = new ByondTest(instanceClient.Byond, instanceClient.Jobs); var chatTest = new ChatTest(instanceClient.ChatBots, instanceManagerClient, instanceClient.Metadata.CloneMetadata()); var configTest = new ConfigurationTest(instanceClient.Configuration, instanceClient.Metadata); + var repoTest = new RepositoryTest(instanceClient.Repository, instanceClient.Jobs); + var repoTests = repoTest.RunPreWatchdog(cancellationToken); var byondTests = byondTest.Run(cancellationToken); var chatTests = chatTest.Run(cancellationToken); await configTest.Run(cancellationToken).ConfigureAwait(false); await byondTests.ConfigureAwait(false); await chatTests.ConfigureAwait(false); + await repoTests; + + await repoTest.RunPostWatchdog(cancellationToken); } } } diff --git a/tests/Tgstation.Server.Tests/Instance/JobsRequiredTest.cs b/tests/Tgstation.Server.Tests/Instance/JobsRequiredTest.cs new file mode 100644 index 0000000000..b25c96c3d9 --- /dev/null +++ b/tests/Tgstation.Server.Tests/Instance/JobsRequiredTest.cs @@ -0,0 +1,68 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tgstation.Server.Api.Models; +using Tgstation.Server.Client.Components; + +namespace Tgstation.Server.Tests.Instance +{ + abstract class JobsRequiredTest + { + protected IJobsClient JobsClient { get; } + + protected JobsRequiredTest(IJobsClient jobsClient) + { + this.JobsClient = jobsClient; + } + + protected async Task WaitForJob(Job originalJob, int timeout, bool expectFailure, CancellationToken cancellationToken) + { + var job = originalJob; + do + { + await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); + job = await JobsClient.GetId(job, cancellationToken).ConfigureAwait(false); + --timeout; + } + while (!job.StoppedAt.HasValue && timeout > 0); + + if (!job.StoppedAt.HasValue) + { + await JobsClient.Cancel(job, cancellationToken).ConfigureAwait(false); + Assert.Fail($"Job ID {job.Id} \"{job.Description}\" timed out!"); + } + + if (expectFailure ^ job.ExceptionDetails != null) + Assert.Fail(job.ExceptionDetails ?? $"Expected job \"{job.Id}\" \"{job.Description}\" to fail but it didn't"); + + return job; + } + + protected async Task WaitForJobProgressThenCancel(Job originalJob, int timeout, CancellationToken cancellationToken) + { + var job = originalJob; + do + { + await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); + job = await JobsClient.GetId(job, cancellationToken).ConfigureAwait(false); + --timeout; + } + while (!job.Progress.HasValue && timeout > 0); + + if (job.StoppedAt.HasValue) + { + await JobsClient.Cancel(job, cancellationToken).ConfigureAwait(false); + Assert.Fail($"Job ID {job.Id} \"{job.Description}\" completed when we wanted it to just progress!"); + } + + if (job.ExceptionDetails != null) + Assert.Fail(job.ExceptionDetails); + + await JobsClient.Cancel(job, cancellationToken); + return await WaitForJob(job, timeout, false, cancellationToken).ConfigureAwait(false); + } + } +} diff --git a/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs b/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs new file mode 100644 index 0000000000..79158f2634 --- /dev/null +++ b/tests/Tgstation.Server.Tests/Instance/RepositoryTest.cs @@ -0,0 +1,207 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Tgstation.Server.Api.Models; +using Tgstation.Server.Client; +using Tgstation.Server.Client.Components; + +namespace Tgstation.Server.Tests.Instance +{ + sealed class RepositoryTest : JobsRequiredTest + { + readonly IRepositoryClient repositoryClient; + + public RepositoryTest(IRepositoryClient repositoryClient, IJobsClient jobsClient) + : base(jobsClient) + { + this.repositoryClient = repositoryClient ?? throw new ArgumentNullException(nameof(repositoryClient)); + } + + public async Task RunPreWatchdog(CancellationToken cancellationToken) + { + // Clone ourselves + var workingBranch = Environment.GetEnvironmentVariable("TGS4_TEST_BRANCH"); + if (String.IsNullOrWhiteSpace(workingBranch)) + workingBranch = Environment.GetEnvironmentVariable("APPVEYOR_REPO_BRANCH"); + if (String.IsNullOrWhiteSpace(workingBranch)) + workingBranch = Environment.GetEnvironmentVariable("TRAVIS_BRANCH"); + if (String.IsNullOrWhiteSpace(workingBranch)) + workingBranch = "master"; + + var initalRepo = await repositoryClient.Read(cancellationToken); + Assert.IsNotNull(initalRepo); + Assert.IsNull(initalRepo.Origin); + Assert.IsNull(initalRepo.Reference); + Assert.IsNull(initalRepo.RevisionInformation); + Assert.IsNull(initalRepo.ActiveJob); + + const string Origin = "https://github.com/tgstation/tgstation-server"; + initalRepo.Origin = Origin; + initalRepo.Reference = workingBranch; + + var clone = await repositoryClient.Clone(initalRepo, cancellationToken).ConfigureAwait(false); + Assert.IsNotNull(clone); + Assert.AreEqual(Origin, clone.Origin); + Assert.AreEqual(workingBranch, clone.Reference); + Assert.IsNull(clone.RevisionInformation); + Assert.IsNotNull(clone.ActiveJob); + + await WaitForJobProgressThenCancel(clone.ActiveJob, 20, cancellationToken).ConfigureAwait(false); + + var secondRead = await repositoryClient.Read(cancellationToken).ConfigureAwait(false); + Assert.IsNotNull(secondRead); + Assert.IsNull(secondRead.ActiveJob); + + clone = await repositoryClient.Clone(initalRepo, cancellationToken).ConfigureAwait(false); + + await WaitForJob(clone.ActiveJob, 120, false, cancellationToken).ConfigureAwait(false); + var cloned = await repositoryClient.Read(cancellationToken); + + Assert.AreEqual(Origin, cloned.Origin); + Assert.AreEqual(workingBranch, cloned.Reference); + Assert.IsNotNull(cloned.RevisionInformation); + Assert.IsNotNull(cloned.RevisionInformation.ActiveTestMerges); + Assert.AreEqual(0, cloned.RevisionInformation.ActiveTestMerges.Count); + Assert.IsNotNull(cloned.RevisionInformation.CommitSha); + Assert.IsNotNull(cloned.RevisionInformation.OriginCommitSha); + Assert.IsNotNull(cloned.RevisionInformation.CompileJobs); + Assert.AreEqual(0, cloned.RevisionInformation.CompileJobs.Count); + Assert.IsNotNull(cloned.RevisionInformation.OriginCommitSha); + Assert.IsNull(cloned.RevisionInformation.PrimaryTestMerge); + Assert.AreEqual(cloned.RevisionInformation.CommitSha, cloned.RevisionInformation.OriginCommitSha); + + cloned.Origin = "https://github.com/tgstation/tgstation"; + await ApiAssert.ThrowsException(() => repositoryClient.Update(cloned, cancellationToken), ErrorCode.RepoCantChangeOrigin); + cloned.Origin = Origin; + + // checkout V3 and back + cloned.Reference = "V3"; + var updated = await Checkout(cloned, false, true, cancellationToken); + + // Specific SHA + updated.CheckoutSha = "f43f5bd"; + await ApiAssert.ThrowsException(() => Checkout(updated, false, false, cancellationToken), ErrorCode.RepoMismatchShaAndReference); + updated.Reference = null; + updated = await Checkout(updated, false, false, cancellationToken); + + // Fake SHA + updated.CheckoutSha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + updated = await Checkout(updated, true, false, cancellationToken); + + // Fake ref + updated.Reference = "Tgs4IntegrationTestFakeBranchNeverNameABranchThis"; + updated = await Checkout(updated, true, true, cancellationToken); + + // Back + updated.Reference = workingBranch; + updated = await Checkout(updated, true, true, cancellationToken); + + var testPRString = Environment.GetEnvironmentVariable("TGS4_TEST_PULL_REQUEST_NUMBER"); + if (String.IsNullOrWhiteSpace(testPRString)) + testPRString = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER"); + if (String.IsNullOrWhiteSpace(testPRString)) + testPRString = Environment.GetEnvironmentVariable("TRAVIS_PULL_REQUEST"); + + if (!String.IsNullOrWhiteSpace(testPRString)) + { + if (!int.TryParse(testPRString, out var prNumber)) + Assert.Inconclusive($"Invalid PR #: {testPRString}"); + await TestMergeTests(updated, prNumber, cancellationToken); + } + } + + async Task Checkout(Repository updated, bool expectFailure, bool isRef, CancellationToken cancellationToken) + { + var newRef = isRef ? updated.Reference : updated.CheckoutSha; + var checkingOut = await repositoryClient.Update(updated, cancellationToken); + Assert.IsNotNull(checkingOut.ActiveJob); + await WaitForJob(checkingOut.ActiveJob, 30, expectFailure, cancellationToken); + var result = await repositoryClient.Read(cancellationToken); + if (!expectFailure) + if (isRef) + Assert.AreEqual(newRef, result.Reference); + else + Assert.IsTrue(result.RevisionInformation.CommitSha.StartsWith(newRef, StringComparison.OrdinalIgnoreCase)); + + Assert.AreEqual(result.RevisionInformation.CommitSha, result.RevisionInformation.OriginCommitSha); + + return result; + } + + async Task TestMergeTests(Repository repository, int prNumber, CancellationToken cancellationToken) + { + repository.NewTestMerges = new List + { + new TestMergeParameters + { + Number = prNumber + } + }; + + var orignCommit = repository.RevisionInformation.OriginCommitSha; + + var numberOnlyMerging = await repositoryClient.Update(repository, cancellationToken); + Assert.IsNotNull(numberOnlyMerging.ActiveJob); + Assert.IsTrue(numberOnlyMerging.ActiveJob.Description.Contains(prNumber.ToString())); + + await WaitForJob(numberOnlyMerging.ActiveJob, 20, false, cancellationToken); + + var withMerge = await repositoryClient.Read(cancellationToken); + Assert.IsNull(withMerge.Reference); + Assert.AreEqual(1, withMerge.RevisionInformation.ActiveTestMerges.Count); + Assert.AreEqual(prNumber, withMerge.RevisionInformation.ActiveTestMerges.First().Number); + Assert.AreEqual(prNumber, withMerge.RevisionInformation.PrimaryTestMerge.Number); + var prRevision = withMerge.RevisionInformation.PrimaryTestMerge.PullRequestRevision; + Assert.IsNotNull(prRevision); + Assert.IsNotNull(withMerge.RevisionInformation.PrimaryTestMerge.MergedBy); + Assert.IsNotNull(withMerge.RevisionInformation.PrimaryTestMerge.MergedAt); + Assert.IsNotNull(withMerge.RevisionInformation.PrimaryTestMerge.Author); + Assert.IsNull(withMerge.RevisionInformation.PrimaryTestMerge.Comment); + Assert.IsNotNull(withMerge.RevisionInformation.PrimaryTestMerge.TitleAtMerge); + Assert.IsNotNull(withMerge.RevisionInformation.PrimaryTestMerge.BodyAtMerge); + Assert.AreEqual($"https://github.com/tgstation/tgstation-server/pull/{prNumber}", withMerge.RevisionInformation.PrimaryTestMerge.Url); + Assert.AreEqual(orignCommit, withMerge.RevisionInformation.OriginCommitSha); + Assert.AreNotEqual(orignCommit, withMerge.RevisionInformation.CommitSha); + + // Reset, do it again with a comment and specific sha + withMerge.UpdateFromOrigin = true; + withMerge.Reference = repository.Reference; + withMerge.NewTestMerges = new List + { + new TestMergeParameters + { + Number = prNumber, + Comment = "asdffdsa", + PullRequestRevision = prRevision + } + }; + + var mergingAgain = await repositoryClient.Update(withMerge, cancellationToken); + Assert.IsNotNull(mergingAgain.ActiveJob); + await WaitForJob(mergingAgain.ActiveJob, 30, false, cancellationToken); + + var final = await repositoryClient.Read(cancellationToken); + Assert.AreEqual("asdffdsa", final.RevisionInformation.PrimaryTestMerge.Comment); + Assert.AreEqual(prNumber, final.RevisionInformation.PrimaryTestMerge.Number); + Assert.AreEqual(prRevision, final.RevisionInformation.PrimaryTestMerge.PullRequestRevision); + } + + public async Task RunPostWatchdog(CancellationToken cancellationToken) + { + + + var deleting = await repositoryClient.Delete(cancellationToken); + Assert.IsNotNull(deleting.ActiveJob); + + await WaitForJob(deleting.ActiveJob, 60, false, cancellationToken).ConfigureAwait(false); + var deleted = await repositoryClient.Read(cancellationToken).ConfigureAwait(false); + + Assert.IsNull(deleted.Origin); + Assert.IsNull(deleted.Reference); + Assert.IsNull(deleted.RevisionInformation); + } + } +}