fix: use command mode when executing powershell scripts on windows (#569)

This commit is contained in:
Gareth
2024-11-19 21:33:13 -08:00
committed by GitHub
parent 7ddd3ff686
commit 95f336b871
2 changed files with 10 additions and 9 deletions
+9 -8
View File
@@ -248,16 +248,17 @@ func TestMultipleBackup(t *testing.T) {
func TestHookExecution(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("skipping test on windows")
}
dir := t.TempDir()
hookOutputBefore := path.Join(dir, "before.txt")
hookOutputAfter := path.Join(dir, "after.txt")
commandBefore := fmt.Sprintf("echo before > %s", hookOutputBefore)
commandAfter := fmt.Sprintf("echo after > %s", hookOutputAfter)
if runtime.GOOS == "windows" {
commandBefore = fmt.Sprintf("echo \"before\" | Out-File -FilePath %q", hookOutputBefore)
commandAfter = fmt.Sprintf("echo \"after\" | Out-File -FilePath %q", hookOutputAfter)
}
sut := createSystemUnderTest(t, &config.MemoryStore{
Config: &v1.Config{
Modno: 1234,
@@ -287,7 +288,7 @@ func TestHookExecution(t *testing.T) {
},
Action: &v1.Hook_ActionCommand{
ActionCommand: &v1.Hook_Command{
Command: "echo before > " + hookOutputBefore,
Command: commandBefore,
},
},
},
@@ -297,7 +298,7 @@ func TestHookExecution(t *testing.T) {
},
Action: &v1.Hook_ActionCommand{
ActionCommand: &v1.Hook_Command{
Command: "echo after > " + hookOutputAfter,
Command: commandAfter,
},
},
},
+1 -1
View File
@@ -34,7 +34,7 @@ func (commandHandler) Execute(ctx context.Context, h *v1.Hook, vars interface{},
// Parse out the shell to use if a #! prefix is present
shell := []string{"sh"}
if runtime.GOOS == "windows" {
shell = []string{"powershell", "-nologo", "-noprofile"}
shell = []string{"powershell", "-NoLogo", "-NoProfile", "-Command", "-"}
}
if len(command) > 2 && command[0:2] == "#!" {