-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_install_script.py
More file actions
137 lines (127 loc) · 2.95 KB
/
Copy pathtest_install_script.py
File metadata and controls
137 lines (127 loc) · 2.95 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"""Integration tests for the Unix installer script."""
import os
import stat
import subprocess
from pathlib import Path
def _write_executable(path: Path, content: str) -> None:
path.write_text(content)
executable_bits = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
path.chmod(path.stat().st_mode | executable_bits)
def test_install_sh_parses_latest_release_tag_on_posix_sed(tmp_path):
repo_root = Path(__file__).resolve().parents[2]
fake_bin = tmp_path / "bin"
fake_bin.mkdir()
install_dir = tmp_path / "install"
calls = tmp_path / "curl-calls.txt"
_write_executable(
fake_bin / "curl",
f"""#!/usr/bin/env sh
set -eu
url=""
for arg do
url="$arg"
done
printf '%s\\n' "$url" >> "{calls}"
case "$url" in
*"/releases/latest")
printf '%s\\n' '{{'
printf '%s\\n' ' "tag_name": "v0.1.0",'
printf '%s\\n' '}}'
;;
*".sha256")
printf '%s\\n' 'expected-sha agentrun-0.1.0-darwin-arm64.tar.gz'
;;
*)
printf '%s\\n' 'fake archive'
;;
esac
""",
)
_write_executable(
fake_bin / "uname",
"""#!/usr/bin/env sh
case "${1:-}" in
-s) printf '%s\n' Darwin ;;
-m) printf '%s\n' arm64 ;;
*) printf '%s\n' Darwin ;;
esac
""",
)
_write_executable(
fake_bin / "sed",
"""#!/usr/bin/env sh
expr=""
while [ "$#" -gt 0 ]; do
case "$1" in
-E)
shift
expr="${1:-}"
;;
*)
expr="$1"
;;
esac
shift || break
done
case "$expr" in
*'[[:space:]]'*)
while IFS= read -r line; do
case "$line" in
*tag_name*)
printf '%s\n' 'v0.1.0'
;;
*)
printf '%s\n' "$line"
;;
esac
done
;;
*)
cat
;;
esac
""",
)
_write_executable(
fake_bin / "tar",
"""#!/usr/bin/env sh
while [ "$#" -gt 0 ]; do
if [ "$1" = "-C" ]; then
shift
install_dir="$1"
break
fi
shift
done
printf '%s\n' '#!/usr/bin/env sh' > "$install_dir/agentrun"
chmod +x "$install_dir/agentrun"
""",
)
_write_executable(
fake_bin / "shasum",
"""#!/usr/bin/env sh
printf '%s\n' 'expected-sha agentrun-0.1.0-darwin-arm64.tar.gz'
""",
)
env = {
**os.environ,
"PATH": f"{fake_bin}:{os.environ.get('PATH', '')}",
"AGENTRUN_INSTALL": str(install_dir),
"AGENTRUN_REPO": "Serverless-Devs/agentrun-cli",
}
result = subprocess.run(
["sh", str(repo_root / "scripts" / "install.sh")],
env=env,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
assert result.returncode == 0, result.stdout + result.stderr
assert "Version: v0.1.0" in result.stdout
assert "Downloading agentrun-0.1.0-darwin-arm64.tar.gz" in result.stdout
assert (install_dir / "agentrun").exists()
assert (
"https://github.com/Serverless-Devs/agentrun-cli/releases/download/"
"v0.1.0/agentrun-0.1.0-darwin-arm64.tar.gz"
) in calls.read_text()