-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for the ingestion of test results from a test result f…
…ile. WIP
- Loading branch information
Showing
19 changed files
with
993 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
RoboClerk.TestResultsFilePlugin/Configuration/TestResultsFilePlugin.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This is the RoboClerk test results file plugin configuration. Using this plugin, | ||
# test results, both system, integration and unit test results can be read from files. | ||
# The plugin is intended to support different file formats. | ||
|
||
# Dependencies file locations array, supports multiple files | ||
|
||
FileLocations = ["{PROJECTROOT}results.json"] | ||
|
||
# The following formats are supported: | ||
# JSON - assumes the following format for the contents of the file: | ||
# [ | ||
# { | ||
# "id": "12264", <--- REQUIRED matching with known test cases / unit tests | ||
# "name": "testLoginSuccess", | ||
# "type": "UNIT", <--- REQUIRED can be either "UNIT" or "SYSTEM" | ||
# "status": "PASS", <----- REQUIRED can be either "PASS" or "FAIL" | ||
# "message": "all good", | ||
# "executionTime": "2023-10-01T12:34:56Z" | ||
# } | ||
# ] |
56 changes: 56 additions & 0 deletions
56
RoboClerk.TestResultsFilePlugin/RoboClerk.TestResultsFilePlugin.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<OutputType>Library</OutputType> | ||
<StartupObject /> | ||
<EnableDynamicLoading>true</EnableDynamicLoading> | ||
<Authors>Meindert Niemeijer</Authors> | ||
<Company>RoboClerk Project</Company> | ||
<Product>Test Results File Plugin</Product> | ||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly> | ||
<Configurations>Debug;Release;ReleasePublish</Configurations> | ||
<BaseOutputPath>bin</BaseOutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleasePublish|AnyCPU'"> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RoboClerk\RoboClerk.csproj"> | ||
<Private>false</Private> | ||
<ExcludeAssets>runtime</ExcludeAssets> | ||
</ProjectReference> | ||
</ItemGroup> | ||
|
||
<Target Name="CopyFiles" AfterTargets="Build" Condition=" '$(Configuration)' == 'ReleasePublish' "> | ||
<ItemGroup> | ||
<PluginFiles Include="$(ProjectDir)$(OutDir)*.dll" /> | ||
</ItemGroup> | ||
|
||
<Copy SourceFiles="@(PluginFiles)" DestinationFolder="$(ProjectDir)../RoboClerkDocker/publish/plugins" /> | ||
<Copy SourceFiles="$(ProjectDir)$(OutDir)RoboClerk.TestResultsFilePlugin.runtimeconfig.json" DestinationFolder="$(ProjectDir)../RoboClerkDocker/publish/plugins" /> | ||
<Copy SourceFiles="$(ProjectDir)$(OutDir)RoboClerk.TestResultsFilePlugin.deps.json" DestinationFolder="$(ProjectDir)../RoboClerkDocker/publish/plugins" /> | ||
</Target> | ||
<Target Name="CopyPlugin" AfterTargets="Build"> | ||
<ItemGroup> | ||
<PluginFiles Include="$(ProjectDir)$(OutDir)*.dll" /> | ||
</ItemGroup> | ||
<Copy SourceFiles="$(ProjectDir)Configuration/TestResultsFilePlugin.toml" DestinationFolder="$(ProjectDir)../RoboClerk/$(OutDir)RoboClerk_input/PluginConfig" /> | ||
<Copy SourceFiles="@(PluginFiles)" DestinationFolder="$(ProjectDir)../RoboClerk/$(OutDir)plugins" /> | ||
</Target> | ||
<Target Name="AdaptConfigFiles" AfterTargets="Build" Condition=" '$(Configuration)' != 'ReleasePublish' "> | ||
<ReplaceFileText | ||
InputFileName="$(ProjectDir)../RoboClerk/$(OutDir)RoboClerk_input/PluginConfig/TestResultsFilePlugin.toml" | ||
MatchExpression="{PROJECTROOT}" | ||
ReplacementText="$(ProjectDir)../" /> | ||
</Target> | ||
<Target Name="AdaptConfigFilesRP" AfterTargets="Build" Condition=" '$(Configuration)' == 'ReleasePublish' "> | ||
<ReplaceFileText | ||
InputFileName="$(ProjectDir)../RoboClerk/$(OutDir)RoboClerk_input/PluginConfig/TestResultsFilePlugin.toml" | ||
MatchExpression="{PROJECTROOT}" | ||
ReplacementText="/mnt/" /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RoboClerk.TestResultsFilePlugin | ||
{ | ||
public class TestResultJSONObject | ||
{ | ||
[JsonPropertyName("id")] | ||
[JsonRequired] | ||
public string? ID { get; set; } | ||
Check warning on line 10 in RoboClerk.TestResultsFilePlugin/TestResultJSONObject.cs
|
||
|
||
[JsonPropertyName("name")] | ||
public string? Name { get; set; } | ||
Check warning on line 13 in RoboClerk.TestResultsFilePlugin/TestResultJSONObject.cs
|
||
|
||
[JsonPropertyName("type")] | ||
[JsonRequired] | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public TestResultType Type { get; set; } | ||
|
||
[JsonPropertyName("status")] | ||
[JsonRequired] | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public TestResultStatus Status { get; set; } | ||
|
||
[JsonPropertyName("message")] | ||
public string? Message { get; set; } | ||
Check warning on line 26 in RoboClerk.TestResultsFilePlugin/TestResultJSONObject.cs
|
||
|
||
[JsonPropertyName("executionTime")] | ||
public DateTime? ExecutionTime { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using RoboClerk.Configuration; | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions; | ||
using System.Text.Json; | ||
using Tomlyn.Model; | ||
using System; | ||
|
||
namespace RoboClerk.TestResultsFilePlugin | ||
{ | ||
public class TestResultsFilePlugin : DataSourcePluginBase | ||
{ | ||
private List<string> fileLocations = new List<string>(); | ||
|
||
public TestResultsFilePlugin(IFileSystem fileSystem) | ||
: base(fileSystem) | ||
{ | ||
name = "TestResultsFilePlugin"; | ||
description = "A plugin that retrieves the test results via one or more files."; | ||
} | ||
|
||
public override void Initialize(IConfiguration configuration) | ||
{ | ||
logger.Info("Initializing the Test Results File Plugin"); | ||
try | ||
{ | ||
var config = GetConfigurationTable(configuration.PluginConfigDir, $"{name}.toml"); | ||
foreach (var item in (TomlArray)config["FileLocations"]) | ||
{ | ||
if (item == null) | ||
{ | ||
logger.Warn($"In the Test Results File Plugin configuration file (\"{name}.toml\"), there is a null valued item in \"FileLocations\"."); | ||
continue; | ||
} | ||
fileLocations.Add((string)item); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.Error("Error reading configuration file for Test Results File plugin."); | ||
logger.Error(e); | ||
throw new Exception("The Test Results File plugin could not read its configuration. Aborting..."); | ||
} | ||
} | ||
|
||
public override void RefreshItems() | ||
{ | ||
logger.Info("Refreshing the test results from file."); | ||
testResults.Clear(); | ||
for (int i = 0; i < fileLocations.Count; i++) | ||
{ | ||
string json = fileSystem.File.ReadAllText(fileLocations[i]); | ||
try | ||
{ | ||
var fileTestResults = JsonSerializer.Deserialize<List<TestResultJSONObject>>(json); | ||
|
||
foreach (var result in testResults) | ||
{ | ||
if (string.IsNullOrEmpty(result.ID)) | ||
throw new JsonException("The 'id' field is required."); | ||
|
||
testResults.Add(new TestResult(result.ID,result.Type,result.Status,result.Name,result.Message,result.ExecutionTime)); | ||
} | ||
} | ||
catch (JsonException) | ||
{ | ||
logger.Error($"Error parsing the file with test results: {fileLocations[i]}"); | ||
throw; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.