File tree Expand file tree Collapse file tree 8 files changed +49
-27
lines changed Expand file tree Collapse file tree 8 files changed +49
-27
lines changed Original file line number Diff line number Diff line change @@ -220,4 +220,35 @@ Describe 'tests for resource discovery' {
220
220
$env: DSC_RESOURCE_PATH = $oldPath
221
221
}
222
222
}
223
+
224
+ It ' DSC_RESOURCE_PATH should be used for executable lookup' {
225
+ $dscTest = Get-Command dscecho - ErrorAction Stop
226
+ $target = if ($IsWindows ) {
227
+ ' echoIt.exe'
228
+ } else {
229
+ ' echoIt'
230
+ }
231
+ Copy-Item - Path " $ ( $dscTest.Source ) " - Destination " $testdrive \$target "
232
+ $manifest = Get-Content - Raw - Path " $ ( Split-Path - Path $dscTest.Source - Parent) \echo.dsc.resource.json" | ConvertFrom-Json
233
+ $manifest.type = ' Test/MyEcho'
234
+ $manifest.get.executable = $target
235
+ $manifest.set = $null
236
+ $manifest.test = $null
237
+ $manifest.schema.command.executable = $target
238
+ Set-Content - Path " $testdrive /test.dsc.resource.json" - Value ($manifest | ConvertTo-Json - Depth 10 )
239
+
240
+ $oldPath = $env: DSC_RESOURCE_PATH
241
+ try {
242
+ $env: DSC_RESOURCE_PATH = $testdrive
243
+ $out = dsc resource get - r ' Test/MyEcho' - i ' {"output":"Custom"}' 2> " $testdrive /error.txt" | ConvertFrom-Json
244
+ $LASTEXITCODE | Should - Be 0
245
+ $out.actualState.output | Should - BeExactly ' Custom'
246
+ dsc resource get - r ' Microsoft.DSC.Debug/Echo' - i ' {"output":"Custom"}' 2> " $testdrive /error.txt" | ConvertFrom-Json
247
+ $LASTEXITCODE | Should - Be 7
248
+ Get-Content - Raw - Path " $testdrive /error.txt" | Should -Match " ERROR.*?Resource not found"
249
+ }
250
+ finally {
251
+ $env: DSC_RESOURCE_PATH = $oldPath
252
+ }
253
+ }
223
254
}
Original file line number Diff line number Diff line change 4
4
Describe ' Discover extension tests' {
5
5
BeforeAll {
6
6
$oldPath = $env: PATH
7
- $separator = [System.IO.Path ]::PathSeparator
8
7
$toolPath = Resolve-Path - Path " $PSScriptRoot /../../extensions/test/discover"
9
- $env: PATH = " $toolPath$separator$ oldPath "
8
+ $env: PATH = " $toolPath " + [ System.IO.Path ]::PathSeparator + $ oldPath
10
9
}
11
10
12
11
AfterAll {
@@ -75,10 +74,10 @@ Describe 'Discover extension tests' {
75
74
Set-Content - Path " $TestDrive /test.dsc.extension.json" - Value $extension_json
76
75
Copy-Item - Path " $toolPath /discover.ps1" - Destination $TestDrive | Out-Null
77
76
Copy-Item - Path " $toolPath /resources" - Destination $TestDrive - Recurse | Out-Null
78
- $env: DSC_RESOURCE_PATH = $TestDrive
77
+ $env: DSC_RESOURCE_PATH = " $TestDrive " + [ System.IO.Path ]::PathSeparator + ( Split-Path ( Get-Command pwsh).Source - Parent)
79
78
try {
80
79
$out = dsc extension list | ConvertFrom-Json
81
- $out.Count | Should - Be 1
80
+ $out.Count | Should - Be 1 - Because ( $out | Out-String )
82
81
$out.type | Should - Be ' Test/DiscoverRelative'
83
82
$out = dsc resource list 2> $TestDrive / error.log
84
83
write-verbose - verbose (Get-Content - Path " $TestDrive /error.log" - Raw)
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ Describe 'tests for resource input' {
85
85
}
86
86
'@
87
87
$oldPath = $env: DSC_RESOURCE_PATH
88
- $env: DSC_RESOURCE_PATH = $TestDrive
88
+ $env: DSC_RESOURCE_PATH = $TestDrive + [ System.IO.Path ]::PathSeparator + $ env: PATH
89
89
Set-Content $TestDrive / EnvVarInput.dsc.resource.json - Value $manifest
90
90
}
91
91
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ changedProperties:
147
147
148
148
$oldPath = $env: DSC_RESOURCE_PATH
149
149
try {
150
- $env: DSC_RESOURCE_PATH = $TestDrive
150
+ $env: DSC_RESOURCE_PATH = $TestDrive + [ System.IO.Path ]::PathSeparator + $ env: PATH
151
151
$out = ' { "test": true }' | dsc resource set - r Test/ SetNoTest -f - -- output- format $format | Out-String
152
152
$LASTEXITCODE | Should - Be 0
153
153
$out.Trim () | Should - BeExactly $expected
@@ -160,7 +160,7 @@ changedProperties:
160
160
It ' set can be used on a resource that does not implement test' {
161
161
$oldPath = $env: DSC_RESOURCE_PATH
162
162
try {
163
- $env: DSC_RESOURCE_PATH = $TestDrive
163
+ $env: DSC_RESOURCE_PATH = $TestDrive + [ System.IO.Path ]::PathSeparator + $ env: PATH
164
164
$out = ' { "test": true }' | dsc resource set - r Test/ SetNoTest -f - | ConvertFrom-Json
165
165
$LASTEXITCODE | Should - Be 0
166
166
$out.BeforeState.test | Should - Be $true
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ couldNotReadSetting = "Could not read 'resourcePath' setting"
72
72
appendingEnvPath = " Appending PATH to resourcePath"
73
73
originalPath = " Original PATH: %{path}"
74
74
failedGetEnvPath = " Failed to get PATH environment variable"
75
+ failedJoinEnvPath = " Failed to join PATH environment variable"
75
76
exeHomeAlreadyInPath = " Exe home is already in path: %{path}"
76
77
addExeHomeToPath = " Adding exe home to path: %{path}"
77
78
usingResourcePath = " Using Resource Path: %{path}"
Original file line number Diff line number Diff line change @@ -149,8 +149,16 @@ impl CommandDiscovery {
149
149
let mut uniques: HashSet < PathBuf > = HashSet :: new ( ) ;
150
150
paths. retain ( |e|uniques. insert ( ( * e) . clone ( ) ) ) ;
151
151
152
- // if exe home is not already in PATH env var then add it to env var and list of searched paths
153
- if !using_custom_path {
152
+ if using_custom_path {
153
+ // when using custom path, intent is to isolate the search of manifests and executables to the custom path
154
+ // so we replace the PATH with the custom path
155
+ if let Ok ( new_path) = env:: join_paths ( paths. clone ( ) ) {
156
+ env:: set_var ( "PATH" , new_path) ;
157
+ } else {
158
+ return Err ( DscError :: Operation ( t ! ( "discovery.commandDiscovery.failedJoinEnvPath" ) . to_string ( ) ) ) ;
159
+ }
160
+ } else {
161
+ // if exe home is not already in PATH env var then add it to env var and list of searched paths
154
162
if let Some ( exe_home) = get_exe_path ( ) ?. parent ( ) {
155
163
let exe_home_pb = exe_home. to_path_buf ( ) ;
156
164
if paths. contains ( & exe_home_pb) {
Original file line number Diff line number Diff line change 2
2
# Licensed under the MIT License.
3
3
4
4
Describe ' tests for runcommandonset get' {
5
- BeforeAll {
6
- $oldPath = $env: DSC_RESOURCE_PATH
7
- $env: DSC_RESOURCE_PATH = Join-Path $PSScriptRoot " .."
8
- }
9
-
10
- AfterAll {
11
- $env: DSC_RESOURCE_PATH = $oldPath
12
- }
13
-
14
5
It ' Input passed for executable, arguments, and exit code' {
15
6
$json = @"
16
7
{
@@ -21,6 +12,7 @@ Describe 'tests for runcommandonset get' {
21
12
"@
22
13
23
14
$result = $json | dsc resource get - r Microsoft.DSC.Transitional/ RunCommandOnSet -f - | ConvertFrom-Json
15
+ $LASTEXITCODE | Should - Be 0
24
16
$result.actualState.arguments | Should - BeExactly @ (' bar' , ' baz' )
25
17
$result.actualState.executable | Should - BeExactly ' foo'
26
18
$result.actualState.exitCode | Should - BeExactly 5
Original file line number Diff line number Diff line change 2
2
# Licensed under the MIT License.
3
3
4
4
Describe ' tests for runcommandonset set' {
5
- BeforeAll {
6
- $oldPath = $env: DSC_RESOURCE_PATH
7
- $env: DSC_RESOURCE_PATH = Join-Path $PSScriptRoot " .."
8
- }
9
-
10
5
AfterEach {
11
6
if (Test-Path $TestDrive / output.txt) {
12
7
Remove-Item - Path $TestDrive / output.txt
13
8
}
14
9
}
15
10
16
- AfterAll {
17
- $env: DSC_RESOURCE_PATH = $oldPath
18
- }
19
-
20
11
It ' Input for executable and arguments can be sent to the resource' {
21
12
$input_json = @"
22
13
{
You can’t perform that action at this time.
0 commit comments