Files
certmanager/cmd/certmanager/terminal_linux_test.go
T
unkin-agent 30eee88d95 Detect a terminal with an ioctl, not a character-device stat
/dev/null is a character device, and so is the /dev/null the Go runtime
reopens onto a closed fd 1, so a bare invocation printed help and exited
zero for both -- the two shapes a machine caller is most likely to hand
the binary.
2026-09-22 23:29:32 +10:00

26 lines
608 B
Go

//go:build linux
package main
import (
"os"
"syscall"
"testing"
)
// The help-and-exit-zero branch is the whole point of the gate, and no CI
// container has a controlling terminal to reach it through /dev/tty. A pty
// allocated from /dev/ptmx is a real terminal, so the true branch is pinned
// here instead of skipped.
func TestIsTerminalDetectsAPTY(t *testing.T) {
pty, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY, 0)
if err != nil {
t.Fatalf("open /dev/ptmx: %v", err)
}
t.Cleanup(func() { _ = pty.Close() })
if !isTerminal(pty) {
t.Error("a pty is a terminal")
}
}