Add integration tests for fetch/slurp, make powershell fetch/slurp work as close as possible to existing fetch/slurp modules.
This commit is contained in:
parent
9a52ee4753
commit
e9c9cab3c8
1 changed files with 31 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue