11BeforeAll {
2- . $PSScriptRoot \Export-DevSetupEnv.ps1
3- . $PSScriptRoot \..\..\..\DevSetup\Private\Utils\Get-DevSetupEnvPath.ps1
4- . $PSScriptRoot \..\..\..\DevSetup\Private\Utils\Get-DevSetupLocalEnvPath.ps1
5- . $PSScriptRoot \..\..\..\DevSetup\Private\Utils\Get-DevSetupCommunityEnvPath.ps1
6- . $PSScriptRoot \..\..\..\DevSetup\Private\Utils\Write-NewConfig.ps1
7- Mock Get-DevSetupEnvPath { " TestDrive:\DevSetupEnvs" }
8- Mock Get-DevSetupLocalEnvPath { " TestDrive:\DevSetupEnvs\local" }
9- Mock Get-DevSetupCommunityEnvPath { " TestDrive:\DevSetupEnvs\community" }
2+ . (Join-Path $PSScriptRoot " Export-DevSetupEnv.ps1" )
3+ . (Join-Path $PSScriptRoot " ..\..\..\DevSetup\Private\Utils\Get-DevSetupEnvPath.ps1" )
4+ . (Join-Path $PSScriptRoot " ..\..\..\DevSetup\Private\Utils\Get-DevSetupLocalEnvPath.ps1" )
5+ . (Join-Path $PSScriptRoot " ..\..\..\DevSetup\Private\Utils\Get-DevSetupCommunityEnvPath.ps1" )
6+ . (Join-Path $PSScriptRoot " ..\..\..\DevSetup\Private\Utils\Write-NewConfig.ps1" )
7+ . (Join-Path $PSScriptRoot " ..\..\..\DevSetup\Private\Utils\Write-StatusMessage.ps1" )
8+ if ($PSVersionTable.PSVersion.Major -eq 5 ) {
9+ Mock Get-DevSetupEnvPath { " $TestDrive \DevSetup\DevSetupEnvs" }
10+ Mock Get-DevSetupLocalEnvPath { " $TestDrive \DevSetup\DevSetupEnvs\local" }
11+ Mock Get-DevSetupCommunityEnvPath { " $TestDrive \DevSetup\DevSetupEnvs\community" }
12+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 ) {
13+ if ($IsWindows ) {
14+ Mock Get-DevSetupEnvPath { " $TestDrive \DevSetup\DevSetupEnvs" }
15+ Mock Get-DevSetupLocalEnvPath { " $TestDrive \DevSetup\DevSetupEnvs\local" }
16+ Mock Get-DevSetupCommunityEnvPath { " $TestDrive \DevSetup\DevSetupEnvs\community" }
17+ }
18+ if ($IsLinux ) {
19+ Mock Get-DevSetupEnvPath { " $TestDrive /home/testuser/DevSetup/DevSetupEnvs" }
20+ Mock Get-DevSetupLocalEnvPath { " $TestDrive /home/testuser/DevSetup/DevSetupEnvs/local" }
21+ Mock Get-DevSetupCommunityEnvPath { " $TestDrive /home/testuser/DevSetup/DevSetupEnvs/community" }
22+ }
23+ if ($IsMacOS ) {
24+ Mock Get-DevSetupEnvPath { " $TestDrive /Users/TestUser/DevSetup/DevSetupEnvs" }
25+ Mock Get-DevSetupLocalEnvPath { " $TestDrive /Users/TestUser/DevSetup/DevSetupEnvs/local" }
26+ Mock Get-DevSetupCommunityEnvPath { " $TestDrive /Users/TestUser/DevSetup/DevSetupEnvs/community" }
27+ }
28+ }
1029 Mock Write-NewConfig { param ($OutFile ) $OutFile }
1130 Mock Write-Host { }
1231 Mock Write-Error { }
32+ Mock Write-StatusMessage { }
1333}
1434
1535Describe " Export-DevSetupEnv" {
1636
1737 Context " When called with a valid name" {
1838 It " Should create the config file and return its path" {
1939 $result = Export-DevSetupEnv - Name " MyEnv"
20- $result | Should - Be " TestDrive:\DevSetupEnvs\local\MyEnv.devsetup"
21- Assert-MockCalled Write-NewConfig - Exactly 1 - Scope It - ParameterFilter { $OutFile -eq " TestDrive:\DevSetupEnvs\local\MyEnv.devsetup" }
22- Assert-MockCalled Write-Host - Scope It - ParameterFilter { $Object -match " exported to" -and $ForegroundColor -eq " Green" }
40+ if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows )) {
41+ $expectedPath = " $TestDrive \DevSetup\DevSetupEnvs\local\MyEnv.devsetup"
42+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux ) {
43+ $expectedPath = " $TestDrive /home/testuser/DevSetup/DevSetupEnvs/local/MyEnv.devsetup"
44+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS ) {
45+ $expectedPath = " $TestDrive /Users/TestUser/DevSetup/DevSetupEnvs/local/MyEnv.devsetup"
46+ }
47+ $result | Should - Be $expectedPath
48+ Assert-MockCalled Write-NewConfig - Exactly 1 - Scope It - ParameterFilter { $OutFile -eq $expectedPath }
49+ Assert-MockCalled Write-StatusMessage - Scope It - ParameterFilter { $Message -match " exported to" -and $ForegroundColor -eq " Green" }
2350 }
2451 }
2552
2653 Context " When called with a valid path" {
2754 It " Should create the config file and return its path" {
28- $result = Export-DevSetupEnv - Path " TestDrive:\MyCustomPath\MyEnv.devsetup"
29- $result | Should - Be " TestDrive:\MyCustomPath\MyEnv.devsetup"
30- Assert-MockCalled Write-NewConfig - Exactly 1 - Scope It - ParameterFilter { $OutFile -eq " TestDrive:\MyCustomPath\MyEnv.devsetup" }
31- Assert-MockCalled Write-Host - Scope It - ParameterFilter { $Object -match " exported to" -and $ForegroundColor -eq " Green" }
55+ if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows )) {
56+ $result = Export-DevSetupEnv - Path " $TestDrive \MyCustomPath\MyEnv.devsetup"
57+ $expectedPath = " $TestDrive \MyCustomPath\MyEnv.devsetup"
58+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux ) {
59+ $result = Export-DevSetupEnv - Path " $TestDrive /MyCustomPath/MyEnv.devsetup"
60+ $expectedPath = " $TestDrive /MyCustomPath/MyEnv.devsetup"
61+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS ) {
62+ $result = Export-DevSetupEnv - Path " $TestDrive /MyCustomPath/MyEnv.devsetup"
63+ $expectedPath = " $TestDrive /MyCustomPath/MyEnv.devsetup"
64+ }
65+ $result | Should - Be $expectedPath
66+ Assert-MockCalled Write-NewConfig - Exactly 1 - Scope It - ParameterFilter { $OutFile -eq $expectedPath }
67+ Assert-MockCalled Write-StatusMessage - Scope It - ParameterFilter { $Message -match " exported to" -and $ForegroundColor -eq " Green" }
3268 }
3369 }
3470
3571 Context " When called with a name that needs sanitization" {
3672 It " Should sanitize the name and warn" {
3773 $result = Export-DevSetupEnv - Name " Data Science Environment!"
38- $result | Should - Be " TestDrive:\DevSetupEnvs\local\DataScienceEnvironment.devsetup"
39- Assert-MockCalled Write-Host - Scope It - ParameterFilter { $Object -match " sanitized" -and $ForegroundColor -eq " Yellow" }
74+ if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows )) {
75+ $expectedPath = " $TestDrive \DevSetup\DevSetupEnvs\local\DataScienceEnvironment.devsetup"
76+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux ) {
77+ $expectedPath = " $TestDrive /home/testuser/DevSetup/DevSetupEnvs/local/DataScienceEnvironment.devsetup"
78+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS ) {
79+ $expectedPath = " $TestDrive /Users/TestUser/DevSetup/DevSetupEnvs/local/DataScienceEnvironment.devsetup"
80+ }
81+ $result | Should - Be $expectedPath
82+ Assert-MockCalled Write-StatusMessage - Scope It - ParameterFilter { $Message -match " sanitized" -and $ForegroundColor -eq " Yellow" }
4083 }
4184 }
4285
4386 Context " When called with a path that needs sanitization" {
4487 It " Should sanitize the path and warn" {
45- $result = Export-DevSetupEnv - Path " TestDrive:\MyCustomPath\MyEnv!.devsetup"
46- $result | Should - Be " TestDrive:\MyCustomPath\MyEnv.devsetup"
47- Assert-MockCalled Write-Host - Scope It - ParameterFilter { $Object -match " sanitized" -and $ForegroundColor -eq " Yellow" }
88+ if ($PSVersionTable.PSVersion.Major -eq 5 -or ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows )) {
89+ $result = Export-DevSetupEnv - Path " $TestDrive \MyCustomPath\MyEnv!.devsetup"
90+ $expectedPath = " $TestDrive \MyCustomPath\MyEnv.devsetup"
91+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux ) {
92+ $result = Export-DevSetupEnv - Path " $TestDrive /MyCustomPath/MyEnv!.devsetup"
93+ $expectedPath = " $TestDrive /MyCustomPath/MyEnv.devsetup"
94+ } elseif ($PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS ) {
95+ $result = Export-DevSetupEnv - Path " $TestDrive /MyCustomPath/MyEnv!.devsetup"
96+ $expectedPath = " $TestDrive /MyCustomPath/MyEnv.devsetup"
97+ }
98+ $result | Should - Be $expectedPath
99+ Assert-MockCalled Write-StatusMessage - Scope It - ParameterFilter { $Message -match " sanitized" -and $ForegroundColor -eq " Yellow" }
48100 }
49101 }
50102
@@ -53,7 +105,7 @@ Describe "Export-DevSetupEnv" {
53105 Mock Write-NewConfig { param ($OutFile ) $null }
54106 $result = Export-DevSetupEnv - Name " FailEnv"
55107 $result | Should - Be $null
56- Assert-MockCalled Write-Error - Exactly 1 - Scope It - ParameterFilter { $Message -match " Failed to create configuration file" }
108+ Assert-MockCalled Write-StatusMessage - Exactly 1 - Scope It - ParameterFilter { $Message -match " Failed to create configuration file" -and $Verbosity -eq " Error " }
57109 }
58110 }
59111}
0 commit comments