-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller_test.go
More file actions
101 lines (90 loc) · 3 KB
/
Copy pathinstaller_test.go
File metadata and controls
101 lines (90 loc) · 3 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
package installer
import (
"testing"
)
func TestInstallMethodString(t *testing.T) {
tests := []struct {
method InstallMethod
expected string
}{
{Homebrew, "homebrew"},
{Binary, "binary"},
{Unknown, "unknown"},
}
for _, tt := range tests {
t.Run(tt.expected, func(t *testing.T) {
if got := tt.method.String(); got != tt.expected {
t.Fatalf("expected %s, got %s", tt.expected, got)
}
})
}
}
func TestIsHomebrewPath(t *testing.T) {
tests := []struct {
name string
path string
expected bool
}{
{"Intel Mac Cellar", "/usr/local/Cellar/stacktodate/0.2.0/bin/stacktodate", true},
{"Apple Silicon", "/opt/homebrew/Cellar/stacktodate/0.2.0/bin/stacktodate", true},
{"Apple Silicon bin", "/opt/homebrew/bin/stacktodate", true},
{"Standard usr local bin", "/usr/local/bin/stacktodate", true},
{"Binary download", "/Users/username/Downloads/stacktodate", false},
{"Build from source", "/Users/username/projects/stacktodate-cli/stacktodate", false},
{"Go workspace", "/home/user/go/bin/stacktodate", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isHomebrewPath(tt.path); got != tt.expected {
t.Fatalf("expected %v, got %v for path %s", tt.expected, got, tt.path)
}
})
}
}
func TestGetUpgradeInstructions(t *testing.T) {
tests := []struct {
name string
method InstallMethod
version string
expected string
}{
{"Homebrew", Homebrew, "v0.3.0", "Upgrade: brew upgrade stacktodate"},
{"Homebrew without v", Homebrew, "0.3.0", "Upgrade: brew upgrade stacktodate"},
{"Binary with v", Binary, "v0.3.0", "Download: https://github.com/stacktodate/stacktodate-cli/releases/tag/v0.3.0"},
{"Binary without v", Binary, "0.3.0", "Download: https://github.com/stacktodate/stacktodate-cli/releases/tag/0.3.0"},
{"Unknown", Unknown, "v0.3.0", "Visit: https://github.com/stacktodate/stacktodate-cli/releases/tag/v0.3.0"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetUpgradeInstructions(tt.method, tt.version); got != tt.expected {
t.Fatalf("expected %q, got %q", tt.expected, got)
}
})
}
}
func TestGetInstallerDownloadURL(t *testing.T) {
tests := []struct {
name string
method InstallMethod
expected string
}{
{"Homebrew", Homebrew, "https://github.com/stacktodate/homebrew-stacktodate"},
{"Binary", Binary, "https://github.com/stacktodate/stacktodate-cli/releases/latest"},
{"Unknown", Unknown, "https://github.com/stacktodate/stacktodate-cli/releases/latest"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetInstallerDownloadURL(tt.method); got != tt.expected {
t.Fatalf("expected %q, got %q", tt.expected, got)
}
})
}
}
func TestDetectInstallMethod(t *testing.T) {
// This test just verifies the function runs without panic
// Actual detection result depends on environment
method := DetectInstallMethod()
if method != Homebrew && method != Binary && method != Unknown {
t.Fatalf("unexpected install method: %v", method)
}
}