|
| 1 | +package installer |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestInstallMethodString(t *testing.T) { |
| 8 | + tests := []struct { |
| 9 | + method InstallMethod |
| 10 | + expected string |
| 11 | + }{ |
| 12 | + {Homebrew, "homebrew"}, |
| 13 | + {Binary, "binary"}, |
| 14 | + {Unknown, "unknown"}, |
| 15 | + } |
| 16 | + |
| 17 | + for _, tt := range tests { |
| 18 | + t.Run(tt.expected, func(t *testing.T) { |
| 19 | + if got := tt.method.String(); got != tt.expected { |
| 20 | + t.Fatalf("expected %s, got %s", tt.expected, got) |
| 21 | + } |
| 22 | + }) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func TestIsHomebrewPath(t *testing.T) { |
| 27 | + tests := []struct { |
| 28 | + name string |
| 29 | + path string |
| 30 | + expected bool |
| 31 | + }{ |
| 32 | + {"Intel Mac Cellar", "/usr/local/Cellar/stacktodate/0.2.0/bin/stacktodate", true}, |
| 33 | + {"Apple Silicon", "/opt/homebrew/Cellar/stacktodate/0.2.0/bin/stacktodate", true}, |
| 34 | + {"Apple Silicon bin", "/opt/homebrew/bin/stacktodate", true}, |
| 35 | + {"Standard usr local bin", "/usr/local/bin/stacktodate", true}, |
| 36 | + {"Binary download", "/Users/username/Downloads/stacktodate", false}, |
| 37 | + {"Build from source", "/Users/username/projects/stacktodate-cli/stacktodate", false}, |
| 38 | + {"Go workspace", "/home/user/go/bin/stacktodate", false}, |
| 39 | + } |
| 40 | + |
| 41 | + for _, tt := range tests { |
| 42 | + t.Run(tt.name, func(t *testing.T) { |
| 43 | + if got := isHomebrewPath(tt.path); got != tt.expected { |
| 44 | + t.Fatalf("expected %v, got %v for path %s", tt.expected, got, tt.path) |
| 45 | + } |
| 46 | + }) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestGetUpgradeInstructions(t *testing.T) { |
| 51 | + tests := []struct { |
| 52 | + name string |
| 53 | + method InstallMethod |
| 54 | + version string |
| 55 | + expected string |
| 56 | + }{ |
| 57 | + {"Homebrew", Homebrew, "v0.3.0", "Upgrade: brew upgrade stacktodate"}, |
| 58 | + {"Homebrew without v", Homebrew, "0.3.0", "Upgrade: brew upgrade stacktodate"}, |
| 59 | + {"Binary with v", Binary, "v0.3.0", "Download: https://github.com/stacktodate/stacktodate-cli/releases/tag/v0.3.0"}, |
| 60 | + {"Binary without v", Binary, "0.3.0", "Download: https://github.com/stacktodate/stacktodate-cli/releases/tag/0.3.0"}, |
| 61 | + {"Unknown", Unknown, "v0.3.0", "Visit: https://github.com/stacktodate/stacktodate-cli/releases/tag/v0.3.0"}, |
| 62 | + } |
| 63 | + |
| 64 | + for _, tt := range tests { |
| 65 | + t.Run(tt.name, func(t *testing.T) { |
| 66 | + if got := GetUpgradeInstructions(tt.method, tt.version); got != tt.expected { |
| 67 | + t.Fatalf("expected %q, got %q", tt.expected, got) |
| 68 | + } |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +func TestGetInstallerDownloadURL(t *testing.T) { |
| 74 | + tests := []struct { |
| 75 | + name string |
| 76 | + method InstallMethod |
| 77 | + expected string |
| 78 | + }{ |
| 79 | + {"Homebrew", Homebrew, "https://github.com/stacktodate/homebrew-stacktodate"}, |
| 80 | + {"Binary", Binary, "https://github.com/stacktodate/stacktodate-cli/releases/latest"}, |
| 81 | + {"Unknown", Unknown, "https://github.com/stacktodate/stacktodate-cli/releases/latest"}, |
| 82 | + } |
| 83 | + |
| 84 | + for _, tt := range tests { |
| 85 | + t.Run(tt.name, func(t *testing.T) { |
| 86 | + if got := GetInstallerDownloadURL(tt.method); got != tt.expected { |
| 87 | + t.Fatalf("expected %q, got %q", tt.expected, got) |
| 88 | + } |
| 89 | + }) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +func TestDetectInstallMethod(t *testing.T) { |
| 94 | + // This test just verifies the function runs without panic |
| 95 | + // Actual detection result depends on environment |
| 96 | + method := DetectInstallMethod() |
| 97 | + |
| 98 | + if method != Homebrew && method != Binary && method != Unknown { |
| 99 | + t.Fatalf("unexpected install method: %v", method) |
| 100 | + } |
| 101 | +} |
0 commit comments