WahlNetwork / vester

Easily validate and remediate your vSphere configuration
https://wahlnetwork.com
Apache License 2.0
146 stars 45 forks source link

Add pester tests for public functions parameters #76

Closed equelin closed 7 years ago

equelin commented 7 years ago

This pester tests checks public functions parameters.

It reads a definition of the function's parameter in a file named Function.Data.ps1. each function has to be declared in that file as long as the function's parameters.

Example of a function declaration:

$Data = @{}

$Data.function1 = @{
    Name = 'Invoke-Vester'
    Parameters = @(
        @{'Name' = 'Config'; 'type' = 'object[]'; 'Mandatory' = $False; 'ValueFromPipeline' = $True; 'ValueFromPipelinebyPropertyName' = $True; 'Aliases' = @('FullName')},
        @{'Name' = 'Test'; 'type' = 'object[]'; 'Mandatory' = $False; 'ValueFromPipeline' = $False; 'ValueFromPipelinebyPropertyName' = $False; 'Aliases' = @('Path','Script')},
        @{'Name' = 'Remediate'; 'type' = 'SwitchParameter'; 'Mandatory' = $False; 'ValueFromPipeline' = $False; 'ValueFromPipelinebyPropertyName' = $False},
        @{'Name' = 'XMLOutputFile'; 'type' = 'object'; 'Mandatory' = $False; 'ValueFromPipeline' = $False; 'ValueFromPipelinebyPropertyName' = $False}
    )
}

The pester's tests in Function.Tests.ps1 will check if there's any drift between the function and it's "desired configuration".

Output of a successfull test:

> Invoke-Pester .\Tests\Function\

Describing No public function left behind
 [+] Function Invoke-Vester is tested 663ms
 [+] Function New-VesterConfig is tested 20ms
Describing Functions Parameters
   Context Invoke-Vester
    [+] Function Invoke-Vester contains Parameter Config 355ms
    [+] Parameter Config type is object[] 17ms
    [+] Parameter Config Mandatory value is False 18ms
    [+] Parameter Config ValueFromPipeline value is True 18ms
    [+] Parameter Config ValueFromPipeline value is True 33ms
    [+] Parameter Config Aliases are FullName 16ms
    [+] Function Invoke-Vester contains Parameter Test 15ms
    [+] Parameter Test type is object[] 15ms
    [+] Parameter Test Mandatory value is False 16ms
    [+] Parameter Test ValueFromPipeline value is False 15ms
    [+] Parameter Test ValueFromPipeline value is False 21ms
    [+] Parameter Test Aliases are Path Script 15ms
    [+] Function Invoke-Vester contains Parameter Remediate 12ms
    [+] Parameter Remediate type is SwitchParameter 14ms
    [+] Parameter Remediate Mandatory value is False 16ms
    [+] Parameter Remediate ValueFromPipeline value is False 16ms
    [+] Parameter Remediate ValueFromPipeline value is False 16ms
    [+] Parameter Remediate has no aliase 17ms
    [+] Function Invoke-Vester contains Parameter XMLOutputFile 16ms
    [+] Parameter XMLOutputFile type is object 18ms
    [+] Parameter XMLOutputFile Mandatory value is False 19ms
    [+] Parameter XMLOutputFile ValueFromPipeline value is False 16ms
    [+] Parameter XMLOutputFile ValueFromPipeline value is False 16ms
    [+] Parameter XMLOutputFile has no aliase 15ms
   Context New-VesterConfig
    [+] Function New-VesterConfig contains Parameter OutputFolder 302ms
    [+] Parameter OutputFolder type is object 12ms
    [+] Parameter OutputFolder Mandatory value is False 14ms
    [+] Parameter OutputFolder ValueFromPipeline value is False 16ms
    [+] Parameter OutputFolder ValueFromPipeline value is False 18ms
    [+] Parameter OutputFolder has no aliase 16ms
    [+] Function New-VesterConfig contains Parameter Quiet 16ms
    [+] Parameter Quiet type is SwitchParameter 17ms
    [+] Parameter Quiet Mandatory value is False 18ms
    [+] Parameter Quiet ValueFromPipeline value is False 20ms
    [+] Parameter Quiet ValueFromPipeline value is False 16ms
    [+] Parameter Quiet has no aliase 15ms