-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcross_platform_test.go
More file actions
71 lines (63 loc) · 1.5 KB
/
cross_platform_test.go
File metadata and controls
71 lines (63 loc) · 1.5 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
// cross_platform_test.go
//go:build !windows
// +build !windows
package main
import (
"testing"
)
// Cross-platform tests that don't depend on Windows APIs
func TestIsVersionNewerCrossPlatform(t *testing.T) {
tests := []struct {
latest string
current string
want bool
}{
{"0.9.9", "0.9.8", true},
{"1.10.0", "1.2.3", true},
{"1.2.3", "1.10.0", false},
{"1.2.3", "1.2.3", false},
{"1.2.3", "2.0.0", false},
{"1.2.3", "invalid", false},
{"1.2.3", "v1.2.3", false},
{"1.2.4", "1.2.3", true},
{"1.2", "1.2.0", false},
{"1.3.0", "1.2.9", true},
{"2.0.0", "1.9.9", true},
{"invalid", "1.2.3", false},
{"v1.10.0", "v1.2.3", true},
{"v1.2.3", "1.2.3", false},
{"v1.2.3", "v1.10.0", false},
{"v1.2.4", "v1.2.3", true},
{"v2.0.0", "v1.9.9", true},
}
for _, tt := range tests {
t.Run(tt.latest+" vs "+tt.current, func(t *testing.T) {
got := isVersionNewer(tt.latest, tt.current)
if got != tt.want {
t.Errorf("isVersionNewer(%q, %q) = %v; want %v", tt.latest, tt.current, got, tt.want)
}
})
}
}
func TestMaxCrossPlatform(t *testing.T) {
tests := []struct {
name string
a int
b int
want int
}{
{"a greater than b", 5, 3, 5},
{"b greater than a", 2, 7, 7},
{"a equals b", 4, 4, 4},
{"negative numbers", -2, -5, -2},
{"zero and positive", 0, 1, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := max(tt.a, tt.b)
if got != tt.want {
t.Errorf("max(%d, %d) = %d, want %d", tt.a, tt.b, got, tt.want)
}
})
}
}