| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "os/exec" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "golang.org/x/sys/windows" |
| 11 | ) |
| 12 | |
| 13 | func TestRelayChildHasNoConsoleAndCapturesOutput(t *testing.T) { |
| 14 | executable, err := os.Executable() |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | cmd := exec.Command(executable, "-test.run=^TestRelayConsoleChild$") |
| 19 | cmd.Env = append(os.Environ(), "CAGE_RELAY_CONSOLE_TEST=1") |
| 20 | configureRelayCommand(cmd) |
| 21 | output, err := cmd.CombinedOutput() |
| 22 | if err != nil || !strings.Contains(string(output), "console=0") || !strings.Contains(string(output), "stderr-captured") { |
| 23 | t.Fatalf("relay child: %s, %v", output, err) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestRelayConsoleChild(t *testing.T) { |
| 28 | if os.Getenv("CAGE_RELAY_CONSOLE_TEST") != "1" { |
| 29 | return |
| 30 | } |
| 31 | window, _, _ := windows.NewLazySystemDLL("kernel32.dll").NewProc("GetConsoleWindow").Call() |
| 32 | fmt.Printf("console=%d\n", window) |
| 33 | fmt.Fprintln(os.Stderr, "stderr-captured") |
| 34 | } |