forked from nikolay-advolodkin/dot-net-sauce
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathTest-SauceConnectState.Tests.ps1
46 lines (43 loc) · 1.97 KB
/
Test-SauceConnectState.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
Describe "Get-KgpConnectionStatus" {
$fakeResponse = New-Object -TypeName psobject
$fakeResponse | Add-Member -MemberType NoteProperty -Name StatusCode -Value 200
Mock ConvertFrom-Json {}
It "Should convert from json if tunnel is up" {
$result = Get-KgpConnectionStatus $fakeResponse
Assert-MockCalled ConvertFrom-Json -Times 1
#Get-KgpConnectionStatus $fakeResponse.StatusCode | Should -Be $true
}
$fakeResponse.StatusCode = 404
It "Should return false if tunnel is down" {
Get-KgpConnectionStatus $fakeResponse | Should -Be $false
}
}
Describe "Test-SauceConnectStatus" {
Mock Get-KgpConnectionStatus {return $true}
Mock Invoke-RestartOperations {}
$result = Test-SauceConnectStatus -IsInfiniteLoop $false
It "Should invoke restart operations when called" {
Assert-MockCalled Invoke-RestartOperations -Times 1
}
It "Should invoke Get-KgpConnectionStatus when called" {
Assert-MockCalled Get-KgpConnectionStatus -Times 1
}
}
Describe "Restart-SauceConnect"{
$SauceConnectFilePath = "c:/fake\bin"
$UserName = "nikolay"
$AccessKey = "abc123"
$TunnelIdentifier = "testTunnel"
Mock Invoke-Expression{}
It "Should form a valid string to execute"{
[string]$Command = Restart-SauceConnect $SauceConnectFilePath $UserName $AccessKey $TunnelIdentifier
$Command | Should -Be "$($SauceConnectFilePath)\sc.exe -u $($UserName) -k $($AccessKey) -i $($TunnelIdentifier) --no-remove-colliding-tunnels -s"
}
It "Should contain bin folder in the path"{
[string]$Command = Restart-SauceConnect $SauceConnectFilePath $UserName $AccessKey $TunnelIdentifier
$Command | Should -BeLike "*bin\sc.exe -u $($UserName) -k $($AccessKey) -i $($TunnelIdentifier) --no-remove-colliding-tunnels -s"
}
}