Skip to content

Commit 490ddbe

Browse files
author
Aliwoto
committed
Add and implement normal RunPowerShell function and tests related to it.
Signed-off-by: Aliwoto <[email protected]>
1 parent 2c25eaf commit 490ddbe

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

ssg/helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ func RunCommand(command string) *ExecuteCommandResult {
256256
return shellUtils.RunCommand(command)
257257
}
258258

259+
func RunPowerShell(command string) *ExecuteCommandResult {
260+
return shellUtils.RunPowerShell(command)
261+
}
262+
259263
func RunCommandAsync(command string) *ExecuteCommandResult {
260264
return shellUtils.RunCommandAsync(command)
261265
}

ssg/shellUtils/helpers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ func RunCommand(command string) *ExecuteCommandResult {
1313
return runCommand(command, false, nil)
1414
}
1515

16+
func RunPowerShell(command string) *ExecuteCommandResult {
17+
return runPowerShell(command, false, nil)
18+
}
19+
1620
func RunCommandAsync(command string) *ExecuteCommandResult {
1721
return runCommand(command, true, nil)
1822
}
@@ -73,7 +77,7 @@ func runPowerShell(command string, isAsync bool, finishedChan chan bool) *Execut
7377
return result
7478
} else {
7579
result = executePowerShell(command, &ExecuteCommandConfig{
76-
TargetRunner: GetCommandTargetRunner(),
80+
TargetRunner: GetPowerShellRunner(),
7781
PrimaryArgs: GetPowerShellPrimaryArgs(),
7882
Stdout: stdout,
7983
Stderr: stderr,
@@ -194,7 +198,7 @@ func executePowerShell(
194198

195199
if config.RemovePowerShellPrompt && !strings.Contains(command, "function prompt") {
196200
// hacky way of getting rid of powershell prompt
197-
command = PowerShellPromptOverride + command
201+
command = PowerShellPromptOverride + "\n" + command
198202
}
199203

200204
cmd = exec.Command(config.TargetRunner, config.PrimaryArgs...)

tests/powershell_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"fmt"
45
"log"
56
"testing"
67

@@ -24,5 +25,23 @@ func TestPowerShell01(t *testing.T) {
2425

2526
result.PurifyPowerShellOutput()
2627

28+
fmt.Println(result.Stdout)
29+
}
30+
31+
func TestPowerShell02(t *testing.T) {
32+
result := ssg.RunPowerShell("$PSVersionTable.PSVersion")
33+
result.PurifyPowerShellOutput()
34+
35+
fmt.Println(result.Stdout)
36+
}
37+
38+
func TestPowerShell03(t *testing.T) {
39+
finishedChan := make(chan bool)
40+
result := ssg.RunPowerShellAsyncWithChan("$PSVersionTable.PSVersion", finishedChan)
41+
42+
<-finishedChan
43+
44+
result.PurifyPowerShellOutput()
45+
2746
log.Println(result.Stdout)
2847
}

0 commit comments

Comments
 (0)