-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_script_test.go
More file actions
78 lines (71 loc) · 1.7 KB
/
Copy pathinstall_script_test.go
File metadata and controls
78 lines (71 loc) · 1.7 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
package brokit_test
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
)
func writeExecutable(t *testing.T, path, content string) {
t.Helper()
if err := os.WriteFile(path, []byte(content), 0755); err != nil {
t.Fatalf("write %s: %v", path, err)
}
}
func TestInstallScriptWindowsZipInstallsExe(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("requires sh-compatible shell")
}
if _, err := exec.LookPath("sh"); err != nil {
t.Skip("sh not available")
}
fakeBin := t.TempDir()
installDir := t.TempDir()
writeExecutable(t, filepath.Join(fakeBin, "uname"), `#!/bin/sh
if [ "$1" = "-s" ]; then
echo MINGW64_NT
else
echo x86_64
fi
`)
writeExecutable(t, filepath.Join(fakeBin, "curl"), `#!/bin/sh
out=""
prev=""
for arg in "$@"; do
if [ "$prev" = "-o" ]; then
out="$arg"
fi
prev="$arg"
done
case "$*" in
*api.github.com*) printf '{"tag_name":"v1.0.0"}' ;;
*) printf 'zip' > "$out" ;;
esac
`)
writeExecutable(t, filepath.Join(fakeBin, "unzip"), `#!/bin/sh
dest=""
prev=""
for arg in "$@"; do
if [ "$prev" = "-d" ]; then
dest="$arg"
fi
prev="$arg"
done
printf 'exe' > "$dest/brokit.exe"
`)
cmd := exec.Command("sh", "install.sh")
cmd.Env = append(os.Environ(),
"PATH="+fakeBin+string(os.PathListSeparator)+os.Getenv("PATH"),
"INSTALL_DIR="+installDir,
)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("install.sh failed: %v\n%s", err, out)
}
if _, err := os.Stat(filepath.Join(installDir, "brokit.exe")); err != nil {
t.Fatalf("expected brokit.exe to be installed: %v\n%s", err, out)
}
if _, err := os.Stat(filepath.Join(installDir, "brokit")); !os.IsNotExist(err) {
t.Fatalf("did not expect extensionless brokit binary, stat err=%v", err)
}
}