File: signal_test.go

package info (click to toggle)
golang-github-moby-sys 0.0~git20241107.638aa7c-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 616 kB
  • sloc: makefile: 58
file content (45 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package signal

import (
	"syscall"
	"testing"
)

func TestParseSignal(t *testing.T) {
	_, err := ParseSignal("0")
	expectedErr := "invalid signal: 0"
	if err == nil || err.Error() != expectedErr {
		t.Errorf("expected  %q, but got %v", expectedErr, err)
	}

	_, err = ParseSignal("SIG")
	expectedErr = "invalid signal: SIG"
	if err == nil || err.Error() != expectedErr {
		t.Errorf("expected  %q, but got %v", expectedErr, err)
	}

	for sigStr := range SignalMap {
		responseSignal, err := ParseSignal(sigStr)
		if err != nil {
			t.Error(err)
		}
		signal := SignalMap[sigStr]
		if responseSignal != signal {
			t.Errorf("expected: %q, got: %q", signal, responseSignal)
		}
	}
}

func TestValidSignalForPlatform(t *testing.T) {
	isValidSignal := ValidSignalForPlatform(syscall.Signal(0))
	if isValidSignal {
		t.Error("expected !isValidSignal")
	}

	for _, sigN := range SignalMap {
		isValidSignal = ValidSignalForPlatform(sigN)
		if !isValidSignal {
			t.Error("expected isValidSignal")
		}
	}
}