-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Yaml validation in the Build script #85
Comments
I used to have this one: https://github.com/gaelcolas/DscInfraSample/blob/master/Tests/01%20ConfigData/ConfigData.Tests.ps1#L19 Is it not in this repo @raandree ? |
I can see the same line in this repo as well:
But I just made a mistake in a Yaml file and this didn't fire...... |
Have been reviewing the ConfigData.Tests file. I noticed that this file checks the Datum.yml file, all Node yml files and the Role yml files. All other Yml files, like location, environment and any other custom layers aren't checked. I have fixed this issue by adding this test to the file: $allDefinitions = Get-ChildItem $here\..\..\DscConfigData -Recurse -Include *.yml
Describe 'Validate All Definition Files' -Tag Integration {
$allDefinitions.ForEach{
# A Node cannot be empty
$content = Get-Content -Path $_ -Raw
$fileName = $_.Name
It "'$fileName' is a valid yaml" {
{ $content | ConvertFrom-Yaml } | Should -Not -Throw
}
}
} |
Thanks, @ykuijs, I have added the test. I am wondering that you did run into this error. If there is a syntax error in one of the yaml files, 'Get-FilteredConfigurationData' should throw an error, one that is not very intuitive. I have added this additionally to https://github.com/gaelcolas/DscInfraSample/blob/master/Tests/01%20ConfigData/ConfigData.Tests.ps1: $configurationData = try {
Get-FilteredConfigurationData -Datum $datum -Filter $filter
}
catch {
Write-Error "'Get-FilteredConfigurationData' did not return any data. Please check if all YAML files are valid and don't have syntax errors"
} |
When you make an error in a Yaml file, the MOF compilation process fails without a nice error message. Would be great to add a Yaml validation step in the pre-Build steps.
The text was updated successfully, but these errors were encountered: