Skip to content

Commit

Permalink
Integrate Yaml Validator into the CI to validate Persistence Test cas…
Browse files Browse the repository at this point in the history
…es (#694)
  • Loading branch information
abaskk-msft authored Jul 8, 2024
1 parent e0246be commit cf28dff
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ jobs:
- name: Test - PAModel
run: dotnet bin/Debug/PAModelTests/PAModelTests.dll

- name: Test - YamlValidator
run: dotnet bin/Debug/YamlValidator.Tests/YamlValidator.Tests.dll

- name: Test - Persistence.Tests Yaml Files (ubuntu & macos)
run: ./scripts/PersistenceValidate.sh
if: ${{ runner.os != 'Windows' }}

- name: Test - Persistence.Tests Yaml Files (windows)
run: ./scripts/PersistenceValidate.ps1
if: ${{ runner.os == 'Windows' }}

- name: Restore workloads for samples
run: dotnet workload restore samples/MauiMsApp/MauiMsApp.csproj

Expand Down
23 changes: 23 additions & 0 deletions scripts/PersistenceValidate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<#
Validate's the Yaml Controls used by Persistence's Unit Tests
Uses the repository's root as entry point (similar to how containers on github actions would)
#>

$AppTestDir = "..\Persistence.Tests\_TestData\AppsWithYaml"
$ControlTestDir = "..\Persistence.Tests\_TestData\ValidYaml-CI"

# come back to same directory after validation
Push-Location

Set-Location -Path "bin\Debug\YamlValidator"

$AppTestResults = dotnet YamlValidator.dll validate --path $AppTestDir
Write-Output "Validating Directory $AppTestDir `n"
$AppTestResults

$ControlTestResults = dotnet YamlValidator.dll validate --path $ControlTestDir
Write-Output "Validating Directory $ControlTestDir `n"
$ControlTestResults

# restore location
Pop-Location
16 changes: 16 additions & 0 deletions scripts/PersistenceValidate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# This script is used to validate whether persistence has valid tests

cd bin/Debug/YamlValidator

APP_TEST_DIR="../Persistence.Tests/_TestData/AppsWithYaml"
CONTROL_TEST_DIR="../Persistence.Tests/_TestData/ValidYaml-CI"

app_test_results=$(dotnet YamlValidator.dll validate --path $APP_TEST_DIR)
printf "Validating Directory $APP_TEST_DIR \n"
printf "$app_test_results"

control_test_results=$(dotnet YamlValidator.dll validate --path $CONTROL_TEST_DIR)
printf "Validating Directory $CONTROL_TEST_DIR \n"
printf "$control_test_results"
6 changes: 4 additions & 2 deletions src/YamlValidator.Tests/YamlValidator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand All @@ -18,8 +20,8 @@
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0-preview.5.24306.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestTestAdapterVersion)" />
<PackageReference Include="MSTest" Version="$(MSTest)" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 0 additions & 7 deletions src/YamlValidator/InputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public static RootCommand GetRootCommand()
{
result.ErrorMessage = $"The path '{inputFilePath}' does not exist";
}
else if (Directory.Exists(inputFilePath))
{
if (Directory.GetFiles(inputFilePath, $"*{Constants.YamlFileExtension}").Length == 0)
{
result.ErrorMessage = $"The folder '{inputFilePath}' does not contain any yaml files";
}
}
else if (File.Exists(inputFilePath))
{
if (!inputFilePath.EndsWith(Constants.YamlFileExtension, StringComparison.OrdinalIgnoreCase))
Expand Down

0 comments on commit cf28dff

Please sign in to comment.