Skip to content

Commit

Permalink
Adding L0 test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivangi authored and Shivangi committed Sep 17, 2019
1 parent f56ed9f commit c36228a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV4/AzurePowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $__vsts_input_errorActionPreference = Get-VstsInput -Name errorActionPreference
$__vsts_input_failOnStandardError = Get-VstsInput -Name FailOnStandardError
$targetAzurePs = Get-VstsInput -Name TargetAzurePs
$customTargetAzurePs = Get-VstsInput -Name CustomTargetAzurePs
$input_pwsh = Get-VstsInput -Name 'pwsh' -AsBool
$input_pwsh = Get-VstsInput -Name 'pwsh'
$input_workingDirectory = Get-VstsInput -Name 'workingDirectory' -Require

# Validate the script path and args do not contains new-lines. Otherwise, it will
Expand Down
28 changes: 28 additions & 0 deletions Tasks/AzurePowerShellV4/Tests/ChecksForPowerShellCore.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[CmdletBinding()]
param()

# Arrange.
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
$targetAzurePs = "4.1.0"
Register-Mock Get-VstsInput { "FilePath" } -- -Name ScriptType -Require
Register-Mock Get-VstsInput { "$PSScriptRoot/PerformsBasicFlow_TargetScript.ps1" } -- -Name ScriptPath
Register-Mock Get-VstsInput { $targetAzurePs } -- -Name TargetAzurePs
Register-Mock Get-VstsInput { 'arg1 arg2' } -- -Name ScriptArguments
Register-Mock Get-VstsInput { "continue" } -- -Name errorActionPreference
Register-Mock Get-VstsInput { $true } -- -Name FailOnStandardError
Register-Mock Get-VstsInput { $true } -- -Name pwsh
Register-Mock Get-VstsInput { ([System.IO.Path]::GetTempPath()) } -- -Name workingDirectory
Register-Mock Update-PSModulePathForHostedAgent
Register-Mock Get-Module
Register-Mock Initialize-AzModule
Register-Mock Get-VstsEndpoint { @{auth = @{ scheme = "ServicePrincipal" }} }
Register-Mock Remove-EndpointSecrets
Register-Mock Disconnect-AzureAndClearContext
Register-Mock Assert-VstsPath
Register-Mock Invoke-VstsTool { }

# Act.
$actual = & $PSScriptRoot\..\AzurePowerShell.ps1

Assert-WasCalled Invoke-VstsTool -Times 1
Assert-WasCalled Invoke-VstsTool -ArgumentsEvaluator {$args.count -eq 6 -and $args[3] -like '*pwsh.exe*'}
6 changes: 3 additions & 3 deletions Tasks/AzurePowerShellV4/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ describe('AzurePowerShell Suite', function () {
});

if (psm.testSupported()) {
it('checks for powershell core', (done) => {
psr.run(path.join(__dirname, 'ChecksForPowerShellCore.ps1'), done);
})
it('performs basic flow', (done) => {
psr.run(path.join(__dirname, 'PerformsBasicFlow.ps1'), done);
})
it('removes functions and variables', (done) => {
psr.run(path.join(__dirname, 'RemovesFunctionsAndVariables.ps1'), done);
})
it('throws when otherversion is specified in a wrong format', (done) => {
psr.run(path.join(__dirname, 'ThrowsForInvalidVersion.ps1'), done);
})
Expand Down
41 changes: 0 additions & 41 deletions Tasks/AzurePowerShellV4/Tests/RemovesFunctionsAndVariables.ps1

This file was deleted.

This file was deleted.

0 comments on commit c36228a

Please sign in to comment.