WEB-1031 Update test to use new test automations capabilities (#21)

* test env setup

* make and fail request

* successful test automation submission

* use new sdk version for tests

* nits
This commit is contained in:
Chuck Driesler
2024-06-06 18:26:41 +01:00
committed by GitHub
parent 0a23ce1699
commit 85e56570c7
6 changed files with 29 additions and 145 deletions
+2
View File
@@ -576,3 +576,5 @@ FodyWeavers.xsd
# Additional files built by Visual Studio
# End of https://www.toptal.com/developers/gitignore/api/dotnetcore,linux,visualstudiocode,rider,visualstudio,windows,macos
appsettings.json
@@ -8,7 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Speckle.Automate.Sdk" Version="2.19.0" />
<PackageReference Include="Speckle.Objects" Version="2.19.0" />
<PackageReference Include="Speckle.Automate.Sdk" Version="2.19.1" />
<PackageReference Include="Speckle.Objects" Version="2.19.1" />
</ItemGroup>
</Project>
+12 -72
View File
@@ -1,91 +1,24 @@
# nullable enable
namespace TestAutomateFunction;
using Speckle.Automate.Sdk.Schema;
using Speckle.Automate.Sdk;
using Speckle.Automate.Sdk.Test;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
using Speckle.Core.Models;
using Speckle.Core.Transports;
using Utils = TestAutomateUtils;
[TestFixture]
public sealed class AutomationContextTest : IDisposable
{
private async Task<AutomationRunData> AutomationRunData(Base testObject)
{
string projectId = await client.StreamCreate(new() { name = "Automate function e2e test" });
const string branchName = "main";
Branch model = await client.BranchGet(projectId, branchName, 1);
string modelId = model.id;
string rootObjId = await Operations.Send(
testObject,
new List<ITransport> { new ServerTransport(client.Account, projectId) }
);
string versionId = await client.CommitCreate(
new()
{
streamId = projectId,
objectId = rootObjId,
branchName = model.name
}
);
var automationName = TestAutomateUtils.RandomString(10);
var automationId = TestAutomateUtils.RandomString(10);
var automationRevisionId = TestAutomateUtils.RandomString(10);
await TestAutomateUtils.RegisterNewAutomation(projectId, modelId, client, automationId, automationName, automationRevisionId);
var automationRunId = TestAutomateUtils.RandomString(10);
var functionId = TestAutomateUtils.RandomString(10);
var functionName = "Automation name " + TestAutomateUtils.RandomString(10);
var functionRelease = TestAutomateUtils.RandomString(10);
return new AutomationRunData
{
ProjectId = projectId,
ModelId = modelId,
BranchName = branchName,
VersionId = versionId,
SpeckleServerUrl = client.ServerUrl,
AutomationId = automationId,
AutomationRevisionId = automationRevisionId,
AutomationRunId = automationRunId,
FunctionId = functionId,
FunctionName = functionName,
FunctionRelease = functionRelease,
};
}
private Client client;
private Account account;
private string GetSpeckleToken()
{
var envVarName = "SPECKLE_TOKEN";
var token = Environment.GetEnvironmentVariable(envVarName);
if (token is null)
{
throw new Exception($"Cannot run tests without a {envVarName} environment variable");
}
return token;
}
private string GetSpeckleServerUrl() =>
Environment.GetEnvironmentVariable("SPECKLE_SERVER_ULR") ?? "http://127.0.0.1:3000";
[OneTimeSetUp]
public void Setup()
{
account = new Account
{
token = GetSpeckleToken(),
serverInfo = new ServerInfo { url = GetSpeckleServerUrl()}
token = TestAutomateEnvironment.GetSpeckleToken(),
serverInfo = new ServerInfo { url = TestAutomateEnvironment.GetSpeckleServerUrl().ToString() }
};
client = new Client(account);
}
@@ -93,12 +26,18 @@ public sealed class AutomationContextTest : IDisposable
[Test]
public async Task TestFunctionRun()
{
var automationRunData = await AutomationRunData(TestAutomateUtils.TestObject());
var inputs = new FunctionInputs
{
SpeckleTypeToCount = "Base",
SpeckleTypeTargetCount = 1
};
var automationRunData = await TestAutomateUtils.CreateTestRun(client);
var automationContext = await AutomationRunner.RunFunction(
AutomateFunction.Run,
automationRunData,
account.token,
new FunctionInputs { SpeckleTypeToCount = "Base" }
inputs
);
Assert.That(automationContext.RunStatus, Is.EqualTo("SUCCEEDED"));
@@ -107,5 +46,6 @@ public sealed class AutomationContextTest : IDisposable
public void Dispose()
{
client.Dispose();
TestAutomateEnvironment.Clear();
}
}
@@ -14,12 +14,16 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
<PackageReference Include="Speckle.Automate.Sdk" Version="2.18.0-fileInput" />
<PackageReference Include="Speckle.Objects" Version="2.17.0-automate3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SpeckleAutomateDotnetExample\SpeckleAutomateDotnetExample.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
-69
View File
@@ -1,69 +0,0 @@
using System.Diagnostics.CodeAnalysis;
using GraphQL;
using Speckle.Core.Api;
using Speckle.Core.Models;
namespace TestAutomateFunction;
public static class TestAutomateUtils
{
[SuppressMessage("Security", "CA5394:Do not use insecure randomness")]
public static string RandomString(int length)
{
Random rand = new();
const string pool = "abcdefghijklmnopqrstuvwxyz0123456789";
var chars = Enumerable.Range(0, length).Select(_ => pool[rand.Next(0, pool.Length)]);
return new string(chars.ToArray());
}
public static Base TestObject()
{
Base rootObject = new() { ["foo"] = "bar" };
return rootObject;
}
public static async Task RegisterNewAutomation(
string projectId,
string modelId,
Client speckleClient,
string automationId,
string automationName,
string automationRevisionId
)
{
GraphQLRequest query =
new(
query: """
mutation CreateAutomation(
$projectId: String!
$modelId: String!
$automationName: String!
$automationId: String!
$automationRevisionId: String!
) {
automationMutations {
create(
input: {
projectId: $projectId
modelId: $modelId
automationName: $automationName
automationId: $automationId
automationRevisionId: $automationRevisionId
}
)
}
}
""",
variables: new
{
projectId,
modelId,
automationName,
automationId,
automationRevisionId,
}
);
await speckleClient.ExecuteGraphQLRequest<object>(query);
}
}
@@ -0,0 +1,6 @@
{
"SpeckleToken": "YOUR-TOKEN-HERE",
"SpeckleServerUrl": "http://127.0.0.1:3000",
"SpeckleProjectId": "YOUR-PROJECT-ID-HERE",
"SpeckleAutomationId": "YOUR-AUTOMATION-ID-HERE"
}