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:
@@ -576,3 +576,5 @@ FodyWeavers.xsd
|
|||||||
# Additional files built by Visual Studio
|
# Additional files built by Visual Studio
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/dotnetcore,linux,visualstudiocode,rider,visualstudio,windows,macos
|
# End of https://www.toptal.com/developers/gitignore/api/dotnetcore,linux,visualstudiocode,rider,visualstudio,windows,macos
|
||||||
|
|
||||||
|
appsettings.json
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Speckle.Automate.Sdk" Version="2.19.0" />
|
<PackageReference Include="Speckle.Automate.Sdk" Version="2.19.1" />
|
||||||
<PackageReference Include="Speckle.Objects" Version="2.19.0" />
|
<PackageReference Include="Speckle.Objects" Version="2.19.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,91 +1,24 @@
|
|||||||
# nullable enable
|
|
||||||
namespace TestAutomateFunction;
|
namespace TestAutomateFunction;
|
||||||
|
|
||||||
using Speckle.Automate.Sdk.Schema;
|
|
||||||
using Speckle.Automate.Sdk;
|
using Speckle.Automate.Sdk;
|
||||||
|
using Speckle.Automate.Sdk.Test;
|
||||||
using Speckle.Core.Api;
|
using Speckle.Core.Api;
|
||||||
using Speckle.Core.Credentials;
|
using Speckle.Core.Credentials;
|
||||||
using Speckle.Core.Models;
|
|
||||||
using Speckle.Core.Transports;
|
|
||||||
using Utils = TestAutomateUtils;
|
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public sealed class AutomationContextTest : IDisposable
|
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 Client client;
|
||||||
private Account account;
|
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]
|
[OneTimeSetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
account = new Account
|
account = new Account
|
||||||
{
|
{
|
||||||
token = GetSpeckleToken(),
|
token = TestAutomateEnvironment.GetSpeckleToken(),
|
||||||
serverInfo = new ServerInfo { url = GetSpeckleServerUrl()}
|
serverInfo = new ServerInfo { url = TestAutomateEnvironment.GetSpeckleServerUrl().ToString() }
|
||||||
};
|
};
|
||||||
client = new Client(account);
|
client = new Client(account);
|
||||||
}
|
}
|
||||||
@@ -93,12 +26,18 @@ public sealed class AutomationContextTest : IDisposable
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task TestFunctionRun()
|
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(
|
var automationContext = await AutomationRunner.RunFunction(
|
||||||
AutomateFunction.Run,
|
AutomateFunction.Run,
|
||||||
automationRunData,
|
automationRunData,
|
||||||
account.token,
|
account.token,
|
||||||
new FunctionInputs { SpeckleTypeToCount = "Base" }
|
inputs
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.That(automationContext.RunStatus, Is.EqualTo("SUCCEEDED"));
|
Assert.That(automationContext.RunStatus, Is.EqualTo("SUCCEEDED"));
|
||||||
@@ -107,5 +46,6 @@ public sealed class AutomationContextTest : IDisposable
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
TestAutomateEnvironment.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,16 @@
|
|||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
|
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
|
||||||
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
|
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
|
<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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SpeckleAutomateDotnetExample\SpeckleAutomateDotnetExample.csproj" />
|
<ProjectReference Include="..\SpeckleAutomateDotnetExample\SpeckleAutomateDotnetExample.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user