pester_configuration replaces instead of updates the default configuration
:ghost: Brief Description
When providing a custom pester_configuration to the verifier, this almost entirely replaces the default configuration defined by the verifier.
Select values from the default hash are actually backfilled with PowerShell code if the provided configuration is missing these values, but not all values from the default hash are backfilled currently:
https://github.com/test-kitchen/kitchen-pester/blob/6d956a61b7f4f8c539a29e456a175a9368809ce4/lib/kitchen/verifier/pester.rb#L279-L303
Version
kitchen-pester v1.1.1
Scenario
I would like to be able to provide a partial pester_configuration where the remaining values are backfilled with the expected defaults instead of having to provide a complete pester_configuration when I only need/want to set one or two additional values differently to the current defaults.
Steps to Reproduce
- Create a kitchen environment with the following verifier configuration:
verifier:
name: pester
pester_install:
MaximumVersion: 5.99.999
MinimumVersion: 5.0.0
Force: true
SkipPublisherCheck: true
pester_configuration:
Output:
Verbosity: Normal
- Have some basic valid Pester test files in a
./tests/folder - Run
kitchen verify - Look to see if you get test results returned to
./testresults/
Expected Result
Test results XML files are returned, respecting the default configuration.
Actual Result
No results file is returned. It seems the verifier doesn't set the pester_configuration.TestResults.Enabled value back to true if the caller is setting any values in pester_configuration, even if the values the caller is setting are unrelated to the TestResults configuration.
:heavy_plus_sign: Additional context
Looking at this SO post it seems like a better option here might be to define the actual default configuration value as { } and then keep the current default config as a predefined field in the verifier class.
When running the Pester tests, we should update our internal default hash values with the hash that test kitchen passes in via configuration rather than allowing user input to accidentally remove useful configuration.
I'm thinking, basically, we set:
default_config :pester_configuration, { )
Then we have this hash which we can copy and update from the Test Kitchen configuration:
def pester_configuration_defaults = {
run: {
path: ".",
PassThru: true,
},
TestResult: {
Enabled: true,
OutputPath: "PesterTestResults.xml",
TestSuiteName: "",
},
Output: {
Verbosity: "Detailed",
},
}
And I think before passing configuration into the powershell code we should be able to do something like this:
class ::Hash
def deep_merge(second)
merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
merge(second.to_h, &merger)
end
end
def final_configuration = pester_configuration_defaults.deep_merge(:pester_configuration)
This would remove the need to manually backfill values, at least for the Pester v5 runs. It might also probably allow us to somewhat simplify the code handling translation to pester v4.
/cc @gaelcolas @gep13 @admiringworm