summaryrefslogtreecommitdiff
path: root/vendor/github.com/AllenDang/w32/create_process_test.go
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2019-01-12 18:39:45 +0100
committerRuben Pollan <meskio@sindominio.net>2019-01-17 12:30:32 +0100
commitb1247d2d0d51108c910a73891ff3116e5f032ab1 (patch)
treee9948964f0bfb1ad2df3bc7bad02aa1f41ccfbd8 /vendor/github.com/AllenDang/w32/create_process_test.go
parentefcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff)
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/github.com/AllenDang/w32/create_process_test.go')
-rw-r--r--vendor/github.com/AllenDang/w32/create_process_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/github.com/AllenDang/w32/create_process_test.go b/vendor/github.com/AllenDang/w32/create_process_test.go
new file mode 100644
index 0000000..7e64b1d
--- /dev/null
+++ b/vendor/github.com/AllenDang/w32/create_process_test.go
@@ -0,0 +1,47 @@
+package w32
+
+import (
+ "testing"
+)
+
+var testProcess = "notepad.exe"
+var wantCode = uint32(42)
+
+func TestCreateProcess(t *testing.T) {
+
+ pi, err := CreateProcessQuick(testProcess)
+ if err != nil {
+ t.Errorf("[!!] Failed to create %s: %s", testProcess, err)
+ } else {
+ t.Logf("[OK] Created process %s with handle 0x%x, PID %d", testProcess, pi.Process, pi.ProcessId)
+ }
+
+ err = TerminateProcess(pi.Process, wantCode)
+ if err != nil {
+ t.Errorf("[!!]Failed to terminate %s: %s", testProcess, err)
+ } else {
+ t.Logf("[OK] Called TerminateProcess on PID %d", pi.ProcessId)
+ }
+
+ err = WaitForSingleObject(pi.Process, 1000) // 1000ms
+ if err != nil {
+ t.Errorf("[!!] failed in WaitForSingleObject: %s", err)
+ } else {
+ t.Logf("[OK] WaitForSingleObject returned...")
+ }
+
+ // make sure we see the magic exit code we asked for
+ code, err := GetExitCodeProcess(pi.Process)
+ if err != nil {
+ t.Errorf("[!!] Failed to get exit code for PID %d: %s", pi.ProcessId, err)
+ } else {
+ t.Logf("[OK] PID %d Exited with code %d", pi.ProcessId, code)
+ }
+ if code != 42 {
+ t.Errorf("[!!] Unexpected exit code for PID %d - want %d, got %d", pi.ProcessId, wantCode, code)
+ }
+
+ CloseHandle(pi.Process)
+ CloseHandle(pi.Thread)
+
+}