Skip to content

Commit

Permalink
Fix bad test mutation operation invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Oct 20, 2024
1 parent 6d391a5 commit 6427938
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions tests/Tgstation.Server.Tests/Live/ApiAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Tgstation.Server.Client;
using Tgstation.Server.Client.GraphQL;

using static HotChocolate.ErrorCodes;

namespace Tgstation.Server.Tests.Live
{
/// <summary>
Expand Down Expand Up @@ -78,6 +80,7 @@ public static async ValueTask OperationFails<TResultData, TPayload>(

var payload = payloadSelector(operationResult.Data);

Assert.AreNotSame<object>(operationResult.Data, payload, "Select the mutation payload from the operation result!");
var payloadErrors = (IEnumerable<object>)payload.GetType().GetProperty("Errors").GetValue(payload);
var error = payloadErrors.Single();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static async ValueTask<TPayload> RunMutationEnsureNoErrors<TResultData, T
var result = await serverClient.RunOperation(operationExecutor, cancellationToken);
result.EnsureNoErrors();
var data = payloadSelector(result.Data);
Assert.AreNotSame<object>(result.Data, data, "Select the mutation payload from the operation result!");
var errorsObject = data.GetType().GetProperty("Errors").GetValue(data);
if (errorsObject != null)
{
Expand Down
18 changes: 9 additions & 9 deletions tests/Tgstation.Server.Tests/Live/TestLiveServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ await adminClient.Execute(
},
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RepositoryBasedServerUpdate.ExecuteAsync(TestUpdateVersion, cancellationToken),
result => result,
result => result.ChangeServerNodeVersionViaTrackedRepository,
cancellationToken));

try
Expand Down Expand Up @@ -549,7 +549,7 @@ await controllerClient.Execute(
},
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RepositoryBasedServerUpdate.ExecuteAsync(TestUpdateVersion, cancellationToken),
result => result,
result => result.ChangeServerNodeVersionViaTrackedRepository,
cancellationToken));

await Task.WhenAny(Task.Delay(TimeSpan.FromMinutes(2)), serverTask);
Expand Down Expand Up @@ -737,7 +737,7 @@ await node1Client.Execute(
cancellationToken),
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RepositoryBasedServerUpdate.ExecuteAsync(TestUpdateVersion, cancellationToken),
result => result,
result => result.ChangeServerNodeVersionViaTrackedRepository,
cancellationToken));
await Task.WhenAny(Task.Delay(TimeSpan.FromMinutes(2)), serverTask);
Assert.IsTrue(serverTask.IsCompleted);
Expand Down Expand Up @@ -786,7 +786,7 @@ await controllerClient2.Execute(
async gqlClient => await ApiAssert.OperationFails(
gqlClient,
gql => gql.RepositoryBasedServerUpdate.ExecuteAsync(TestUpdateVersion, cancellationToken),
result => result,
result => result.ChangeServerNodeVersionViaTrackedRepository,
Client.GraphQL.ErrorCode.SwarmIntegrityCheckFailed,
cancellationToken));

Expand Down Expand Up @@ -988,7 +988,7 @@ await controllerClient.Execute(
restClient => restClient.Administration.Restart(cancellationToken),
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RestartServer.ExecuteAsync(cancellationToken),
result => result,
result => result.RestartServerNode,
cancellationToken));

await Task.WhenAny(
Expand Down Expand Up @@ -1016,7 +1016,7 @@ await node2Client.Execute(
restClient => restClient.Administration.Restart(cancellationToken),
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RestartServer.ExecuteAsync(cancellationToken),
result => result,
result => result.RestartServerNode,
cancellationToken));
await Task.WhenAny(
node2Task,
Expand Down Expand Up @@ -1685,7 +1685,7 @@ await firstAdminMultiClient.Execute(
restClient => restClient.Administration.Restart(cancellationToken),
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RestartServer.ExecuteAsync(cancellationToken),
result => result,
result => result.RestartServerNode,
cancellationToken));
}
catch
Expand Down Expand Up @@ -1835,7 +1835,7 @@ await multiClient.Execute(
restClient => restClient.Administration.Restart(cancellationToken),
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RestartServer.ExecuteAsync(cancellationToken),
result => result,
result => result.RestartServerNode,
cancellationToken));
}

Expand Down Expand Up @@ -1907,7 +1907,7 @@ await adminClient.Execute(
restClient => restClient.Administration.Restart(cancellationToken),
async gqlClient => await gqlClient.RunMutationEnsureNoErrors(
gql => gql.RestartServer.ExecuteAsync(cancellationToken),
result => result,
result => result.RestartServerNode,
cancellationToken));
}

Expand Down

0 comments on commit 6427938

Please sign in to comment.