-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Invoke-Git] Return Object & Change to Public Function (#80)
- `Invoke-Git` - Converted to public function. - Updated to use `System.Diagnostics.Process` for improved error handling. - Returns object, allowing caller to process result.
- Loading branch information
Showing
8 changed files
with
332 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,50 +31,64 @@ InModuleScope $script:moduleName { | |
} | ||
|
||
Context 'When calling Invoke-Git' { | ||
It 'Should call without throwing' { | ||
{ | ||
Invoke-Git -WorkingDirectory $TestDrive -Arguments @( 'config', '--local', 'user.email', '[email protected]' ) | ||
} | Should -Not -Throw | ||
BeforeAll { | ||
$mockProcess | Add-Member -MemberType ScriptProperty -Name 'StandardOutput' -Value { | ||
New-Object -TypeName 'Object' | ` | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Output Message 0' } -PassThru -Force | ||
} -Force | ||
|
||
Assert-VerifiableMock | ||
$mockProcess | Add-Member -MemberType ScriptProperty -Name 'StandardError' -Value { | ||
New-Object -TypeName 'Object' | ` | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Error Message 0' } -PassThru -Force | ||
} -Force | ||
} | ||
} | ||
It 'Should complete with ExitCode=0' { | ||
|
||
Context 'When calling Invoke-Git with an access token' { | ||
BeforeAll { | ||
Mock -CommandName Write-Debug | ||
} | ||
$result = Invoke-Git -WorkingDirectory $TestDrive ` | ||
-Arguments @( 'config', '--local', 'user.email', '[email protected]' ) | ||
|
||
It 'Should call git but mask access token in debug message' { | ||
{ | ||
Invoke-Git -WorkingDirectory $TestDrive ` | ||
-Arguments @( 'remote', 'set-url', 'origin', 'https://name:[email protected]/repository.wiki.git' ) ` | ||
-Debug | ||
} | Should -Not -Throw | ||
$result.ExitCode | Should -BeExactly 0 | ||
|
||
Assert-MockCalled -CommandName Write-Debug -ParameterFilter { | ||
$Message -match 'https://name:[email protected]/repository.wiki.git' | ||
} -Exactly -Times 1 -Scope It | ||
$result.StandardOutput | Should -BeExactly 'Standard Output Message 0' | ||
|
||
$result.StandardError | Should -BeExactly 'Standard Error Message 0' | ||
|
||
Assert-VerifiableMock | ||
} | ||
} | ||
|
||
Context 'When git exits with error code 1' { | ||
Context 'When calling Invoke-Git with an access token' { | ||
BeforeAll { | ||
$mockProcess | Add-Member -MemberType ScriptProperty -Name ExitCode -Value { 1 } -Force | ||
} | ||
|
||
It 'Should not throw an exception' { | ||
{ | ||
Invoke-Git -WorkingDirectory $TestDrive -Arguments @( 'status' ) | ||
} | Should -Not -Throw | ||
$mockProcess | Add-Member -MemberType ScriptProperty -Name 'StandardOutput' -Value { | ||
New-Object -TypeName 'Object' | ` | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Output Message 1' } -PassThru -Force | ||
} -Force | ||
|
||
Assert-VerifiableMock | ||
$mockProcess | Add-Member -MemberType ScriptProperty -Name 'StandardError' -Value { | ||
New-Object -TypeName 'Object' | ` | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Error Message 1' } -PassThru -Force | ||
} -Force | ||
|
||
Mock -CommandName Write-Debug | ||
} | ||
It 'Should return 1' { | ||
$returnCode = Invoke-Git -WorkingDirectory $TestDrive -Arguments @( 'status' ) | ||
$returnCode | Should -BeExactly 1 | ||
|
||
It 'Should complete with ExitCode=1 and mask access token in debug message' { | ||
|
||
$result = Invoke-Git -WorkingDirectory $TestDrive ` | ||
-Arguments @( 'remote', 'set-url', 'origin', 'https://name:[email protected]/repository.wiki.git' ) ` | ||
-Debug | ||
|
||
$result.ExitCode | Should -BeExactly 1 | ||
|
||
$result.StandardOutput | Should -BeExactly 'Standard Output Message 1' | ||
|
||
$result.StandardError | Should -BeExactly 'Standard Error Message 1' | ||
|
||
Assert-MockCalled -CommandName Write-Debug -ParameterFilter { | ||
$Message -match 'https://name:[email protected]/repository.wiki.git' | ||
} -Exactly -Times 1 -Scope It | ||
|
||
Assert-VerifiableMock | ||
} | ||
|
@@ -86,24 +100,23 @@ InModuleScope $script:moduleName { | |
|
||
$mockProcess | Add-Member -MemberType ScriptProperty -Name 'StandardOutput' -Value { | ||
New-Object -TypeName 'Object' | ` | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Output Message' } -PassThru -Force | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Output Message 128' } -PassThru -Force | ||
} -Force | ||
|
||
$mockProcess | Add-Member -MemberType ScriptProperty -Name 'StandardError' -Value { | ||
New-Object -TypeName 'Object' | ` | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Error Message' } -PassThru -Force | ||
Add-Member -MemberType ScriptMethod -Name 'ReadToEnd' -Value { 'Standard Error Message 128' } -PassThru -Force | ||
} -Force | ||
|
||
Mock -CommandName Write-Warning | ||
} | ||
|
||
It 'Should produce ExitCode=128 and Write-Warning' { | ||
$returnCode = Invoke-Git -WorkingDirectory $TestDrive -Arguments @( 'status' ) | ||
$returnCode | Should -BeExactly '128' | ||
It 'Should complete with ExitCode=128' { | ||
$result = Invoke-Git -WorkingDirectory $TestDrive -Arguments @( 'status' ) | ||
|
||
Assert-MockCalled -CommandName Write-Warning -ParameterFilter { | ||
$Message -eq $($localizedData.UnexpectedInvokeGitReturnCode -f $mockProcess.ExitCode) | ||
} -Exactly -Times 1 -Scope It | ||
$result.ExitCode | Should -BeExactly 128 | ||
|
||
$result.StandardOutput | Should -BeExactly 'Standard Output Message 128' | ||
|
||
$result.StandardError | Should -BeExactly 'Standard Error Message 128' | ||
|
||
Assert-VerifiableMock | ||
} | ||
|
Oops, something went wrong.