-
Notifications
You must be signed in to change notification settings - Fork 23
/
command_windows_test.go
46 lines (35 loc) · 1.09 KB
/
command_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"strings"
"syscall"
"testing"
"time"
"unsafe"
"github.com/stretchr/testify/assert"
)
func TestCommand_ExecuteStderr(t *testing.T) {
cmd := NewCommand("echo hello 1>&2")
err := cmd.Execute()
assert.Nil(t, err)
assertEqualWithLineBreak(t, "hello ", cmd.Stderr())
}
func TestCommand_WithTimeout(t *testing.T) {
cmd := NewCommand("timeout 0.005;", WithTimeout(5*time.Millisecond))
err := cmd.Execute()
assert.NotNil(t, err)
// This is needed because windows sometimes can not kill the process :(
containsMsg := strings.Contains(err.Error(), "timeout occurred and can not kill process with pid") || strings.Contains(err.Error(), "command timed out after 5ms")
assert.True(t, containsMsg)
}
func TestCommand_WithValidTimeout(t *testing.T) {
cmd := NewCommand("timeout 0.01;", WithTimeout(1000*time.Millisecond))
err := cmd.Execute()
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)
}