Skip to content
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

Open
ykuijs opened this issue Oct 8, 2020 · 4 comments
Open

Add a Yaml validation in the Build script #85

ykuijs opened this issue Oct 8, 2020 · 4 comments

Comments

@ykuijs
Copy link
Member

ykuijs commented Oct 8, 2020

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.

@gaelcolas
Copy link
Member

@ykuijs
Copy link
Member Author

ykuijs commented Oct 8, 2020

I can see the same line in this repo as well:

{ $datumYamlContent | ConvertFrom-Yaml } | Should -Not -Throw

But I just made a mistake in a Yaml file and this didn't fire......

@ykuijs
Copy link
Member Author

ykuijs commented Oct 9, 2020

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
        }
    }
}

@raandree
Copy link
Contributor

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"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants