Fix tests

This commit is contained in:
Jordan Brown
2020-05-25 17:09:30 -04:00
parent db2601bf50
commit 1652ed80eb
3 changed files with 21 additions and 23 deletions
@@ -179,10 +179,6 @@ namespace Tgstation.Server.Host.Components.Repository
try
{
var libGitRepo = await repositoryFactory.CreateFromPath(ioManager.ResolvePath(), cancellationToken).ConfigureAwait(false);
if (libGitRepo == null)
return null;
return new Repository(
libGitRepo,
commands,
@@ -195,17 +191,17 @@ namespace Tgstation.Server.Host.Components.Repository
semaphore.Release();
});
}
catch (RepositoryNotFoundException e)
catch
{
logger.LogDebug("Repository not found!");
logger.LogTrace("Exception: {0}", e);
return null;
semaphore.Release();
throw;
}
}
catch
catch (RepositoryNotFoundException e)
{
semaphore.Release();
throw;
logger.LogDebug("Repository not found!");
logger.LogTrace("Exception: {0}", e);
return null;
}
}
@@ -179,7 +179,7 @@ namespace Tgstation.Server.Host.Controllers
if (repoManager.CloneInProgress)
return Conflict(new ErrorMessage(ErrorCode.RepoCloning));
if(repoManager.InUse)
if (repoManager.InUse)
return Conflict(new ErrorMessage(ErrorCode.RepoBusy));
using var repo = await repoManager.LoadRepository(cancellationToken).ConfigureAwait(false);
@@ -314,8 +314,7 @@ namespace Tgstation.Server.Host.Controllers
[ProducesResponseType(typeof(Repository), 200)]
[ProducesResponseType(typeof(Repository), 202)]
[ProducesResponseType(410)]
#pragma warning disable CA1502 // TODO: Decomplexify
#pragma warning disable CA1505
#pragma warning disable CA1502, CA1505 // TODO: Decomplexify
public async Task<IActionResult> Update([FromBody]Repository model, CancellationToken cancellationToken)
{
if (model == null)
@@ -825,7 +824,6 @@ namespace Tgstation.Server.Host.Controllers
api.ActiveJob = job.ToApi();
return Accepted(api);
}
#pragma warning restore CA1502
#pragma warning restore CA1505
#pragma warning restore CA1502, CA1505
}
}
@@ -43,6 +43,7 @@ namespace Tgstation.Server.Tests.Instance
initalRepo.Reference = workingBranch;
var clone = await repositoryClient.Clone(initalRepo, cancellationToken).ConfigureAwait(false);
await ApiAssert.ThrowsException<ConflictException>(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoCloning);
Assert.IsNotNull(clone);
Assert.AreEqual(Origin, clone.Origin);
Assert.AreEqual(workingBranch, clone.Reference);
@@ -79,26 +80,26 @@ namespace Tgstation.Server.Tests.Instance
// checkout V3 and back
cloned.Reference = "V3";
var updated = await Checkout(cloned, false, true, cancellationToken);
var updated = await Checkout(cloned, false, true, true, cancellationToken);
// Specific SHA
updated.CheckoutSha = "f43f5bd";
await ApiAssert.ThrowsException<ApiConflictException>(() => Checkout(updated, false, false, cancellationToken), ErrorCode.RepoMismatchShaAndReference);
await ApiAssert.ThrowsException<ApiConflictException>(() => Checkout(updated, false, false, false, cancellationToken), ErrorCode.RepoMismatchShaAndReference);
updated.Reference = null;
updated = await Checkout(updated, false, false, cancellationToken);
updated = await Checkout(updated, false, false, false, cancellationToken);
// Fake SHA
updated.Reference = null;
updated.CheckoutSha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
updated = await Checkout(updated, true, false, cancellationToken);
updated = await Checkout(updated, true, false, false, cancellationToken);
// Fake ref
updated.Reference = "Tgs4IntegrationTestFakeBranchNeverNameABranchThis";
updated = await Checkout(updated, true, true, cancellationToken);
updated = await Checkout(updated, true, true, false, cancellationToken);
// Back
updated.Reference = workingBranch;
updated = await Checkout(updated, false, true, cancellationToken);
updated = await Checkout(updated, false, true, false, cancellationToken);
var testPRString = Environment.GetEnvironmentVariable("TGS4_TEST_PULL_REQUEST_NUMBER");
if (String.IsNullOrWhiteSpace(testPRString))
@@ -117,11 +118,14 @@ namespace Tgstation.Server.Tests.Instance
await TestMergeTests(updated, prNumber, cancellationToken);
}
async Task<Repository> Checkout(Repository updated, bool expectFailure, bool isRef, CancellationToken cancellationToken)
async Task<Repository> Checkout(Repository updated, bool expectFailure, bool isRef, bool checkBusy, CancellationToken cancellationToken)
{
var newRef = isRef ? updated.Reference : updated.CheckoutSha;
var checkingOut = await repositoryClient.Update(updated, cancellationToken);
Assert.IsNotNull(checkingOut.ActiveJob);
if(checkBusy)
await ApiAssert.ThrowsException<ConflictException>(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoBusy);
await WaitForJob(checkingOut.ActiveJob, 30, expectFailure, cancellationToken);
var result = await repositoryClient.Read(cancellationToken);
if (!expectFailure)