Skip to content

Commit

Permalink
Add WithUser for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Nov 15, 2022
1 parent 5cccbdc commit 280a0b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions command_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ package cmd

import (
"os/exec"
"syscall"
)

func createBaseCommand(c *Command) *exec.Cmd {
cmd := exec.Command(`C:\windows\system32\cmd.exe`, "/C", c.Command)
return cmd
}

func WithUser(token syscall.Token) func(c *Command) {
return func(c *Command) {
c.baseCommand.SysProcAttr = &syscall.SysProcAttr{
Token: token,
}
}
}
13 changes: 12 additions & 1 deletion command_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cmd

import (
"github.com/stretchr/testify/assert"
"strings"
"syscall"
"testing"
"time"
"unsafe"

"github.com/stretchr/testify/assert"
)

func TestCommand_ExecuteStderr(t *testing.T) {
Expand Down Expand Up @@ -34,3 +37,11 @@ func TestCommand_WithValidTimeout(t *testing.T) {

assert.Nil(t, err)
}

func TestCommand_WithUser(t *testing.T) {
onehundred := 100
token := syscall.Token(uintptr(unsafe.Pointer(&onehundred)))
cmd := NewCommand("echo hello", WithUser(token))
err := cmd.Execute()
assert.Error(t, err)
}

0 comments on commit 280a0b2

Please sign in to comment.