Skip to content

Commit a3af130

Browse files
committed
adding tests
1 parent 2eee3af commit a3af130

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

process/interrupt_unix_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build !windows
2+
3+
package process
4+
5+
import (
6+
"os"
7+
"os/signal"
8+
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestSendInterrupt(t *testing.T) {
15+
sigChan := make(chan os.Signal, 1)
16+
signal.Notify(sigChan, os.Interrupt)
17+
defer signal.Stop(sigChan)
18+
19+
SendInterrupt()
20+
21+
select {
22+
case sig := <-sigChan:
23+
require.Equal(t, os.Interrupt, sig)
24+
case <-time.After(2 * time.Second):
25+
t.Fatal("timeout waiting for interrupt signal")
26+
}
27+
}

process/interrupt_windows_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//go:build windows
2+
3+
package process
4+
5+
import "testing"
6+
7+
func TestSendInterrupt(t *testing.T) {
8+
// On Windows CI (GitHub Actions), GenerateConsoleCtrlEvent may not work
9+
// as expected without a proper console attached.
10+
// This test verifies the function doesn't panic and the syscall loads correctly.
11+
defer func() {
12+
if r := recover(); r != nil {
13+
t.Fatalf("SendInterrupt panicked: %v", r)
14+
}
15+
}()
16+
17+
// Just verify it doesn't crash - the actual signal delivery
18+
// depends on console configuration which varies in CI
19+
SendInterrupt()
20+
}

0 commit comments

Comments
 (0)