-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_test.go
More file actions
147 lines (122 loc) · 3.2 KB
/
Copy pathruntime_test.go
File metadata and controls
147 lines (122 loc) · 3.2 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package env
import "testing"
// resetRuntime restores runtime shims so tests remain isolated.
func resetRuntime() {
goos = "linux"
goarch = "amd64"
}
// TestOSAndArch ensures runtime identity helpers expose the active platform values.
func TestOSAndArch(t *testing.T) {
defer resetRuntime()
goos = "windows"
goarch = "arm64"
if OS() != "windows" {
t.Fatalf("expected OS() == windows, got %s", OS())
}
if Arch() != "arm64" {
t.Fatalf("expected Arch() == arm64, got %s", Arch())
}
}
// TestIsLinux ensures Linux detection does not overlap unrelated operating systems.
func TestIsLinux(t *testing.T) {
defer resetRuntime()
goos = "linux"
if !IsLinux() {
t.Fatalf("expected IsLinux() == true")
}
if !IsUnix() {
t.Fatalf("linux should be unix-like")
}
if IsMac() || IsWindows() {
t.Fatalf("linux should not be mac/windows")
}
}
// TestIsMac ensures Darwin detection does not overlap unrelated operating systems.
func TestIsMac(t *testing.T) {
defer resetRuntime()
goos = "darwin"
if !IsMac() {
t.Fatalf("expected IsMac() == true")
}
if !IsUnix() {
t.Fatalf("darwin should be unix-like")
}
if IsLinux() || IsWindows() {
t.Fatalf("mac should not be linux/windows")
}
}
// TestIsWindows ensures Windows detection does not overlap unrelated operating systems.
func TestIsWindows(t *testing.T) {
defer resetRuntime()
goos = "windows"
if !IsWindows() {
t.Fatalf("expected IsWindows() == true")
}
if IsUnix() {
t.Fatalf("windows should not be unix-like")
}
if IsLinux() || IsMac() {
t.Fatalf("windows should not be linux/mac")
}
}
// TestIsBSD ensures every supported BSD runtime is recognized.
func TestIsBSD(t *testing.T) {
defer resetRuntime()
for _, bsd := range []string{"freebsd", "openbsd", "netbsd", "dragonfly"} {
goos = bsd
if !IsBSD() {
t.Fatalf("expected IsBSD() == true for %s", bsd)
}
if !IsUnix() {
t.Fatalf("bsd should be unix-like: %s", bsd)
}
if IsLinux() || IsWindows() || IsMac() {
t.Fatalf("bsd should not be linux/windows/mac: %s", bsd)
}
}
}
// TestIsBSD_False ensures non-BSD Unix systems are not misclassified.
func TestIsBSD_False(t *testing.T) {
defer resetRuntime()
goos = "linux"
if IsBSD() {
t.Fatalf("expected IsBSD() == false for linux")
}
}
// TestIsUnix ensures the documented Unix family is recognized without including Windows.
func TestIsUnix(t *testing.T) {
defer resetRuntime()
unixSystems := []string{
"linux", "darwin", "freebsd", "openbsd", "netbsd", "dragonfly",
"solaris", "aix",
}
for _, sys := range unixSystems {
goos = sys
if !IsUnix() {
t.Fatalf("expected IsUnix() == true for %s", sys)
}
}
nonUnix := []string{"windows", "plan9"}
for _, sys := range nonUnix {
goos = sys
if IsUnix() {
t.Fatalf("expected IsUnix() == false for %s", sys)
}
}
}
// TestIsContainerOS ensures container-oriented runtime identifiers remain distinguishable from host kernels.
func TestIsContainerOS(t *testing.T) {
defer resetRuntime()
goos = "linux"
if !IsContainerOS() {
t.Fatalf("expected linux to be container OS")
}
goos = "darwin"
if IsContainerOS() {
t.Fatalf("expected macOS NOT to be container OS")
}
goos = "windows"
if IsContainerOS() {
t.Fatalf("expected windows NOT to be container OS")
}
}