From 1c45062f1136c9e213ecf47b462e1c9d4f1f7da2 Mon Sep 17 00:00:00 2001 From: "Cory Knox (He/Him)" <30301021+corbob@users.noreply.github.com> Date: Sun, 3 Apr 2022 09:08:26 -0700 Subject: [PATCH] (#88) Add instance name replacement of destination (#89) * (#88) Add instance name replacement of destination Replace %{instance_name} with the instance name in the destination of the downloads key. Signed-off-by: Cory Knox * (#88) Add test results to Azure Pipelines Add the test results to the Azure Pipelines runs. Signed-off-by: Cory Knox --- .kitchen.appveyor.yml | 2 ++ .kitchen.yml | 2 ++ README.md | 11 ++++++++++- TESTING.md | 1 + azure-pipelines.yml | 4 ++++ lib/kitchen/verifier/pester.rb | 3 ++- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.kitchen.appveyor.yml b/.kitchen.appveyor.yml index 31eccb0..51f5121 100644 --- a/.kitchen.appveyor.yml +++ b/.kitchen.appveyor.yml @@ -19,6 +19,8 @@ verifier: environment: API_KEY: Some key value PUSH_REPO: https://push.example.com + downloads: + "PesterTestResults.xml": "testresults/%{instance_name}/" suites: - name: default diff --git a/.kitchen.yml b/.kitchen.yml index 5984bb0..7c5e388 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -18,6 +18,8 @@ verifier: environment: API_KEY: Some key value PUSH_REPO: https://push.example.com + downloads: + "PesterTestResults.xml": "testresults/%{instance_name}/" suites: - name: default diff --git a/README.md b/README.md index 5e3b2e8..c376b71 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,16 @@ This is necessary in certain cases, such as when `pwsh` is installed via `snap` * `downloads`- map[string, string], defaults to `{"./PesterTestResults.xml" => "./testresults}"`. Files to download from SUT to local system, used to download the pester results localy. -The key is the remote file (relative to verifier folder or absolute), the value is the directory (ends with / or \\) it should be saved to (relative to pwd or absolute). +The key is the remote file to download, while the value is the destination. + * The source can: + * Be relative to the verifier folder (by default `$TEMP/verifier`) + * Be absolute on the system (e.g. `/var/tmp/file.zip` or `C:\\Windows\\Temp\\file.zip`) + * The destination can: + * Include `%{instance_name}` to indicate the Test Kitchen instance name + * Be a directory (ends in `/` or `\\`) + * Be relative to the Current Working Directory + * Be absolute + ```yaml downloads: PesterTestResults.xml: "./output/testResults/" diff --git a/TESTING.md b/TESTING.md index fe688b1..5add867 100644 --- a/TESTING.md +++ b/TESTING.md @@ -9,3 +9,4 @@ The general steps to test your changes: 1. Build new gem: `chef gem build ./kitchen-pester.gemspec` 1. Install built gem: `chef gem install ./kitchen-pester-.gem` 1. Test with `test-kitchen`: `kitchen test` +1. Ensure that `PesterTestResults.xml` is created in `./testresults/default-windows-2016` diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 37271fe..aaa389e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -59,6 +59,10 @@ stages: displayName: Run Tests env: SPEC_OPTS: --format progress + - task: PublishTestResults@2 + inputs: + testResultsFormat: NUnit + testResultsFiles: 'testresults/**/PesterTestResults.xml' - job: Package dependsOn: Validate condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/main'), notIn(variables['Build.Reason'], 'PullRequest')) diff --git a/lib/kitchen/verifier/pester.rb b/lib/kitchen/verifier/pester.rb index 6dc212c..3884525 100644 --- a/lib/kitchen/verifier/pester.rb +++ b/lib/kitchen/verifier/pester.rb @@ -190,6 +190,7 @@ def resolve_downloads_paths! config[:downloads] = config[:downloads] .map do |source, destination| source = source.to_s + destination = destination.gsub("%{instance_name}", instance.name) info(" resolving remote source's absolute path.") unless source.match?('^/|^[a-zA-Z]:[\\/]') # is Absolute? info(" '#{source}' is a relative path, resolving to: #{File.join(config[:root_path], source)}") @@ -203,7 +204,7 @@ def resolve_downloads_paths! if !File.directory?(File.dirname(destination)) FileUtils.mkdir_p(File.dirname(destination)) else - info(" Directory #{File.dirname(destination)} seem to exist.") + info(" Directory #{File.dirname(destination)} seems to exist.") end [ source, destination ]