Skip to content

Commit

Permalink
(chocolatey#74) Add test for bootstrap script
Browse files Browse the repository at this point in the history
Made sense to move the test package files into a subfolder, so did that
in order to keep test files a bit more organised.
  • Loading branch information
vexx32 committed Jun 27, 2022
1 parent c491eaa commit 2850ac1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
test_choco_path: '{{ win_output_dir }}\win_chocolatey'
test_choco_bootstrap_script: '{{ win_output_dir }}\test-bootstrap.ps1'
test_choco_source: '{{ test_choco_path }}\packages'
test_choco_source2: '{{ test_choco_path }}\packages2' # used to verify source works with the source name and not just the path
test_choco_package1: ansible
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This is a minimal bootstrap script which simply pulls the default bootstrap
# script from community.chocolatey.org and then uses that to install Chocolatey.
# Afterwards, a file is created so we can confirm this bootstrap script was
# indeed used to install Chocolatey.

$protocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::SecurityProtocol = $protocol

$client = New-Object System.Net.WebClient
$scriptContent = $client.DownloadString("https://community.chocolatey.org/install.ps1")
$filePath = "$PSScriptRoot/install.ps1"

$scriptContent | Set-Content -Path $filePath

$ErrorActionPreference = 'Stop'

# Parameters aren't needed; our Ansible installation process sets all the parameters
# with environment variables before running the bootstrap script.
& $filePath

$temp = "C:\temp"
if (-not (Test-Path $temp)) {
New-Item -ItemType Directory -Path $temp -Force > $null
}
[pscustomobject]@{ bootstrap = $true } | Set-Content -Path "$temp\confirm-bootstrap.txt"
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@

- name: copy template package files
win_copy:
src: files/
src: files/test-package/
dest: '{{ test_choco_path }}'

- name: copy test bootstrap script
win_copy:
src: files/bootstrap.ps1
dest: '{{ test_choco_bootstrap_script }}'

# run the setup in 1 shell script to save on test time
- name: set up packages
win_shell: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,21 @@
that:
- not remove_nonexistent_version is changed
- '"{{ test_choco_package1 }}|0.1.0" in remove_nonexistent_version_result.stdout_lines'

- name: remove existing Chocolatey installation
win_shell: Remove-Item -Path "C:/ProgramData/chocolatey" -Recurse -Force

- name: install Chocolatey using the test bootstrap script
win_chocolatey:
name: chocolatey
state: present
bootstrap_script: "{{ test_choco_bootstrap_script }}"

- name: checking if the bootstrap file has been created
win_shell: Get-Content -Path "C:/temp/confirm-bootstrap.txt" -Raw
register: bootstrap_file_check

- name: assert bootstrap file has been created
assert:
that:
- (bootstrap_file_check.stdout|from_json).bootstrap

0 comments on commit 2850ac1

Please sign in to comment.