File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -220,4 +220,32 @@ 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
+ }
247
+ finally {
248
+ $env: DSC_RESOURCE_PATH = $oldPath
249
+ }
250
+ }
223
251
}
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.failedSetEnvPath" ) . 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) {
You can’t perform that action at this time.
0 commit comments