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

Separated ps module_util test targets, added WebRequest tests #67914

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: call module with AddType tests
add_type_test:
register: add_type_test

- name: assert call module with AddType tests
assert:
that:
- not add_type_test is failed
- add_type_test.res == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Ansible.Command
}
'@

Function Run-Process($executable, $arguments) {
Function Invoke-Process($executable, $arguments) {
$proc = New-Object System.Diagnostics.Process
$psi = $proc.StartInfo
$psi.FileName = $executable
Expand Down Expand Up @@ -72,7 +72,7 @@ foreach ($expected in $tests) {
$joined_string = Argv-ToString -arguments $expected
# We can't used CommandLineToArgvW to test this out as it seems to mangle
# \, might be something to do with unicode but not sure...
$actual = Run-Process -executable $exe -arguments $joined_string
$actual = Invoke-Process -executable $exe -arguments $joined_string

if ($expected.Count -ne $actual.Count) {
$result.actual = $actual -join "`n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- setup_win_printargv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: call module with ArgvParser tests
argv_parser_test:
exe: '{{ win_printargv_path }}'
register: argv_test

- assert:
that:
- argv_test.data == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ $tests = @{

"Test backup file in check mode" = {
$orig_file = Join-Path -Path $tmp_dir -ChildPath "file-check.txt"
Set-Content -Path $orig_file -Value "abc"
Set-Content -LiteralPath $orig_file -Value "abc"
$actual = Backup-File -path $orig_file -WhatIf

(Test-Path -LiteralPath $actual) | Assert-Equals -Expected $false

$parent_dir = Split-Path -Path $actual
$parent_dir = Split-Path -LiteralPath $actual
$backup_file = Split-Path -Path $actual -Leaf
$parent_dir | Assert-Equals -Expected $tmp_dir
($backup_file -match "^file-check\.txt\.$pid\.\d{8}-\d{6}\.bak$") | Assert-Equals -Expected $true
Expand All @@ -66,16 +66,16 @@ $tests = @{
"Test backup file" = {
$content = "abc"
$orig_file = Join-Path -Path $tmp_dir -ChildPath "file.txt"
Set-Content -Path $orig_file -Value $content
Set-Content -LiteralPath $orig_file -Value $content
$actual = Backup-File -path $orig_file

(Test-Path -LiteralPath $actual) | Assert-Equals -Expected $true

$parent_dir = Split-Path -Path $actual
$parent_dir = Split-Path -LiteralPath $actual
$backup_file = Split-Path -Path $actual -Leaf
$parent_dir | Assert-Equals -Expected $tmp_dir
($backup_file -match "^file\.txt\.$pid\.\d{8}-\d{6}\.bak$") | Assert-Equals -Expected $true
(Get-Content -Path $actual -Raw) | Assert-Equals -Expected "$content`r`n"
(Get-Content -LiteralPath $actual -Raw) | Assert-Equals -Expected "$content`r`n"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: call module with BackupFile tests
backup_file_test:
register: backup_file_test

- name: assert call module with BackupFile tests
assert:
that:
- not backup_file_test is failed
- backup_file_test.res == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: call module with camel conversion tests
camel_conversion_test:
register: camel_conversion

- assert:
that:
- camel_conversion.data == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Assert-Equals -actual $actual.stdout -expected "💩`n"
Assert-Equals -actual $actual.stderr -expected ""

$test_name = "test default environment variable"
Set-Item -Path env:TESTENV -Value "test"
Set-Item -LiteralPath env:TESTENV -Value "test"
$actual = Run-Command -command "cmd.exe /c set"
$env_present = $actual.stdout -split "`r`n" | Where-Object { $_ -eq "TESTENV=test" }
if ($null -eq $env_present) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- setup_win_printargv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: call module with CommandUtil tests
command_util_test:
exe: '{{ win_printargv_path }}'
register: command_util

- assert:
that:
- command_util.data == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: call module with FileUtil tests
file_util_test:
register: file_util_test

- assert:
that:
- file_util_test.data == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# They are being run as part of the Windows smoke tests. Please do not significantly
# increase the size of these tests, as the smoke tests need to remain fast.
# Any significant additions should be made to the (as yet nonexistent) PS module_utils unit tests.

---
- name: find a nonexistent drive letter
raw: foreach($c in [char[]]([char]'D'..[char]'Z')) { If (-not $(Get-PSDrive $c -ErrorAction SilentlyContinue)) { return $c } }
register: bogus_driveletter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: call module with symbolic link tests
symbolic_link_test:
register: symbolic_link

- assert:
that:
- symbolic_link.data == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: call module with PrivilegeUtil tests
privilege_util_test:
register: privilege_util_test

- assert:
that:
- privilege_util_test.data == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
windows
shippable/windows/group1
shippable/windows/smoketest
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- block:
- name: create test user with well know SID as the name
win_user:
name: S-1-0-0
password: AbcDef123!@#
state: present

- name: call module with SID tests
sid_utils_test:
sid_account: S-1-0-0
register: sid_test

always:
- name: remove test SID user
win_user:
name: S-1-0-0
state: absent

- assert:
that:
- sid_test.data == 'success'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
windows
shippable/windows/group1
shippable/windows/smoketest
needs/httptester