-
Notifications
You must be signed in to change notification settings - Fork 784
/
plugin_update_command.bats
114 lines (97 loc) · 4.54 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
#!/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 ]
}