-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_test.go
More file actions
87 lines (76 loc) · 1.93 KB
/
install_test.go
File metadata and controls
87 lines (76 loc) · 1.93 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
package mapcli
import (
"os"
"os/exec"
"strings"
"testing"
)
func TestInstallScriptExists(t *testing.T) {
_, err := os.Stat("install.sh")
if os.IsNotExist(err) {
t.Fatal("install.sh does not exist")
}
if err != nil {
t.Fatalf("failed to stat install.sh: %v", err)
}
}
func TestInstallScriptExecutable(t *testing.T) {
info, err := os.Stat("install.sh")
if err != nil {
t.Fatalf("failed to stat install.sh: %v", err)
}
// Check if executable bit is set for owner
if info.Mode()&0100 == 0 {
t.Error("install.sh should be executable")
}
}
func TestInstallScriptSyntax(t *testing.T) {
cmd := exec.Command("bash", "-n", "install.sh")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("install.sh has syntax errors: %v\n%s", err, output)
}
}
func TestInstallScriptContent(t *testing.T) {
content, err := os.ReadFile("install.sh")
if err != nil {
t.Fatalf("failed to read install.sh: %v", err)
}
script := string(content)
// Check for required elements
checks := []struct {
name string
contains string
}{
{"shebang", "#!/bin/bash"},
{"repo reference", "pmarsceill/mapcli"},
{"OS detection", "uname -s"},
{"arch detection", "uname -m"},
{"GitHub API", "api.github.com"},
{"install dir", "INSTALL_DIR"},
{"error handling", "set -e"},
{"linux support", "linux"},
{"darwin support", "darwin"},
{"amd64 support", "amd64"},
{"arm64 support", "arm64"},
}
for _, check := range checks {
t.Run(check.name, func(t *testing.T) {
if !strings.Contains(script, check.contains) {
t.Errorf("install.sh should contain %q", check.contains)
}
})
}
}
func TestInstallScriptShellcheck(t *testing.T) {
// Skip if shellcheck is not installed
_, err := exec.LookPath("shellcheck")
if err != nil {
t.Skip("shellcheck not installed")
}
cmd := exec.Command("shellcheck", "install.sh")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("shellcheck found issues:\n%s", output)
}
}