package installer import ( "errors" "fmt" "os" "strings" "testing" "time" ) func TestDetectionProbeHelperProcess(t *testing.T) { mode := "" for i, arg := range os.Args { if arg == "detection-probe-helper" && i+1 < len(os.Args) { mode = os.Args[i+1] break } } if mode == "" { return } switch mode { case "locale": _, _ = fmt.Fprintf(os.Stdout, "%s/%s", os.Getenv("LC_ALL"), os.Getenv("LANG")) case "flood": _, _ = fmt.Fprint(os.Stdout, strings.Repeat("x", detectionProbeMaxBytes+1024)) case "sleep": time.Sleep(detectionProbeTimeout + time.Second) default: os.Exit(2) } } func runDetectionProbeHelper(t *testing.T, mode string) ([]byte, error) { t.Helper() return runDetectionProbe(os.Args[0], "-test.run=^TestDetectionProbeHelperProcess$", "--", "detection-probe-helper", mode) } func TestRunDetectionProbeUsesStableLocale(t *testing.T) { output, err := runDetectionProbeHelper(t, "locale") if err != nil { t.Fatal(err) } if !strings.HasPrefix(string(output), "C/C") { t.Fatalf("probe locale = %q, want C/C prefix", output) } } func TestRunDetectionProbeCapsOutput(t *testing.T) { output, err := runDetectionProbeHelper(t, "flood") if !errors.Is(err, errDetectionProbeOutputLimit) { t.Fatalf("error = %v, want output-limit error", err) } if len(output) > detectionProbeMaxBytes { t.Fatalf("output length = %d, cap = %d", len(output), detectionProbeMaxBytes) } }