forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_update_command.bats
232 lines (188 loc) · 9.06 KB
/
plugin_update_command.bats
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env bats
load test_helpers
setup() {
setup_asdf_dir
install_mock_plugin_repo "dummy"
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
}
teardown() {
clean_asdf_dir
}
@test "asdf plugin-update should pull latest default branch (refs/remotes/origin/HEAD) for plugin" {
run asdf plugin-update dummy
repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating dummy to master"* ]]
[ "$repo_head" = "master" ]
}
@test "asdf plugin-update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if default branch changes" {
install_mock_plugin_repo "dummy-remote"
remote_dir="$BASE_DIR/repo-dummy-remote"
# set HEAD to refs/head/main in dummy-remote
git -C "${remote_dir}" checkout -b main
# track & fetch remote repo (dummy-remote) in plugin (dummy)
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote remove origin
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote add origin "$remote_dir"
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" fetch origin
run asdf plugin-update dummy
repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating dummy to main"* ]]
[ "$repo_head" = "main" ]
}
@test "asdf plugin-update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if the default branch contains a forward slash" {
install_mock_plugin_repo "dummy-remote"
remote_dir="$BASE_DIR/repo-dummy-remote"
# set HEAD to refs/head/my/default in dummy-remote
git -C "${remote_dir}" checkout -b my/default
# track & fetch remote repo (dummy-remote) in plugin (dummy)
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote remove origin
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote add origin "$remote_dir"
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" fetch origin
run asdf plugin-update dummy
repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating dummy to my/default"* ]]
[ "$repo_head" = "my/default" ]
}
@test "asdf plugin-update should pull latest default branch (refs/remotes/origin/HEAD) for plugin even if already set to specific ref" {
# set plugin to specific sha
current_sha="$(git --git-dir "${BASE_DIR}/repo-dummy/.git" --work-tree "$BASE_DIR/repo-dummy" rev-parse HEAD)"
run asdf plugin-update dummy "${current_sha}"
# setup mock plugin remote
install_mock_plugin_repo "dummy-remote"
remote_dir="$BASE_DIR/repo-dummy-remote"
# set HEAD to refs/head/main in dummy-remote
git -C "${remote_dir}" checkout -b main
# track & fetch remote repo (dummy-remote) in plugin (dummy)
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote remove origin
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" remote add origin "$remote_dir"
git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" fetch origin
# update plugin to the default branch
run asdf plugin-update dummy
repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy/.git" --work-tree "$ASDF_DIR/plugins/dummy" rev-parse --abbrev-ref HEAD)"
[ "$status" -eq 0 ]
[[ "$output" =~ "Updating dummy to main"* ]]
[ "$repo_head" = "main" ]
}
@test "asdf plugin-update should not remove plugin versions" {
run asdf install dummy 1.1
[ "$status" -eq 0 ]
[ "$(cat "$ASDF_DIR/installs/dummy/1.1/version")" = "1.1" ]
run asdf plugin-update dummy
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/installs/dummy/1.1/version" ]
run asdf plugin-update --all
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/installs/dummy/1.1/version" ]
}
@test "asdf plugin-update should not remove plugins" {
# dummy plugin is already installed
run asdf plugin-update dummy
[ "$status" -eq 0 ]
[ -d "$ASDF_DIR/plugins/dummy" ]
run asdf plugin-update --all
[ "$status" -eq 0 ]
[ -d "$ASDF_DIR/plugins/dummy" ]
}
@test "asdf plugin-update should not remove shims" {
run asdf install dummy 1.1
[ -f "$ASDF_DIR/shims/dummy" ]
run asdf plugin-update dummy
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/shims/dummy" ]
run asdf plugin-update --all
[ "$status" -eq 0 ]
[ -f "$ASDF_DIR/shims/dummy" ]
}
@test "asdf plugin-update done for all plugins" {
local command="asdf plugin-update --all"
# Count the number of update processes remaining after the update command is completed.
run bash -c "${command} >/dev/null && ps -o 'ppid,args' | awk '{if(\$1==1 && \$0 ~ /${command}/ ) print}' | wc -l"
[[ 0 -eq "$output" ]]
}
@test "asdf plugin-update executes post-plugin update script" {
local plugin_path
plugin_path="$(get_plugin_path dummy)"
old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
run asdf plugin-update dummy
new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
[[ "$output" = *"${expected_output}" ]]
}
@test "asdf plugin-update executes post-plugin update script if git-ref updated" {
local plugin_path
plugin_path="$(get_plugin_path dummy)"
old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
# setup mock plugin remote
install_mock_plugin_repo "dummy-remote"
remote_dir="$BASE_DIR/repo-dummy-remote"
# set HEAD to refs/head/main in dummy-remote
git -C "${remote_dir}" checkout -b main
# track & fetch remote repo (dummy-remote) in plugin (dummy)
git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" remote remove origin
git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" remote add origin "$remote_dir"
git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" fetch origin
# update plugin to the default branch
run asdf plugin-update dummy
new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
[[ "$output" = *"${expected_output}" ]]
}
@test "asdf plugin-update executes configured pre hook (generic)" {
cat >"$HOME/.asdfrc" <<-'EOM'
pre_asdf_plugin_update = echo UPDATE ${@}
EOM
local plugin_path
plugin_path="$(get_plugin_path dummy)"
old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
run asdf plugin-update dummy
new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
[[ "$output" = *"UPDATE dummy"*"${expected_output}" ]]
}
@test "asdf plugin-update executes configured pre hook (specific)" {
cat >"$HOME/.asdfrc" <<-'EOM'
pre_asdf_plugin_update_dummy = echo UPDATE
EOM
local plugin_path
plugin_path="$(get_plugin_path dummy)"
old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
run asdf plugin-update dummy
new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}"
[[ "$output" = *"UPDATE"*"${expected_output}" ]]
}
@test "asdf plugin-update executes configured post hook (generic)" {
cat >"$HOME/.asdfrc" <<-'EOM'
post_asdf_plugin_update = echo UPDATE ${@}
EOM
local plugin_path
plugin_path="$(get_plugin_path dummy)"
old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
run asdf plugin-update dummy
new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}
UPDATE dummy"
[[ "$output" = *"${expected_output}" ]]
}
@test "asdf plugin-update executes configured post hook (specific)" {
cat >"$HOME/.asdfrc" <<-'EOM'
post_asdf_plugin_update_dummy = echo UPDATE
EOM
local plugin_path
plugin_path="$(get_plugin_path dummy)"
old_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
run asdf plugin-update dummy
new_ref="$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" rev-parse --short HEAD)"
local expected_output="plugin updated path=${plugin_path} old git-ref=${old_ref} new git-ref=${new_ref}
UPDATE"
[[ "$output" = *"${expected_output}" ]]
}
@test "asdf plugin-update prints the location of plugin (specific)" {
local plugin_path
plugin_path="$(get_plugin_path dummy)"
run asdf plugin-update dummy
local expected_output="Location of dummy plugin: $plugin_path"
[[ "$output" == *"$expected_output"* ]]
}