From e9c9cab3c85b54ea9e6684867de4ac66c00556cd Mon Sep 17 00:00:00 2001 From: Chris Church Date: Wed, 18 Jun 2014 16:10:10 -0500 Subject: [PATCH] Add integration tests for fetch/slurp, make powershell fetch/slurp work as close as possible to existing fetch/slurp modules. --- windows/slurp.ps1 | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/windows/slurp.ps1 b/windows/slurp.ps1 index 40bb5eba033..da2404d02f9 100644 --- a/windows/slurp.ps1 +++ b/windows/slurp.ps1 @@ -22,26 +22,43 @@ $params = Parse-Args $args; $src = ''; If ($params.src.GetType) { - $src = $params.src; + $src = $params.src; } Else { - If ($params.path.GetType) - { - $src = $params.path; - } + If ($params.path.GetType) + { + $src = $params.path; + } } If (-not $src) { - + $result = New-Object psobject @{}; + Fail-Json $result "missing required argument: src"; } -$bytes = [System.IO.File]::ReadAllBytes($src); -$content = [System.Convert]::ToBase64String($bytes); +If (Test-Path $src) +{ + If ((Get-Item $src).Directory) # Only files have the .Directory attribute. + { + $bytes = [System.IO.File]::ReadAllBytes($src); + $content = [System.Convert]::ToBase64String($bytes); -$result = New-Object psobject @{ - changed = $false - encoding = "base64" -}; -Set-Attr $result "content" $content; -Exit-Json $result; + $result = New-Object psobject @{ + changed = $false + encoding = "base64" + }; + Set-Attr $result "content" $content; + Exit-Json $result; + } + Else + { + $result = New-Object psobject @{}; + Fail-Json $result ("is a directory: " + $src); + } +} +Else +{ + $result = New-Object psobject @{}; + Fail-Json $result ("file not found: " + $src); +}