Skip to content

Commit 280f06c

Browse files
authored
Merge pull request #4 from NReilingh/lockfile-checking
Lockfile checking
2 parents 5f9d096 + 43b5cfd commit 280f06c

File tree

6 files changed

+79
-10
lines changed

6 files changed

+79
-10
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ jobs:
3030
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
3131
with:
3232
formula-name: archive-fusionvm
33-
homebrew-tap: nreilingh/homebrew-nreilingh
33+
homebrew-tap: nreilingh/homebrew-tap
3434
download-url: ${{ steps.upload_release_asset.outputs.browser_download_url }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/tests/_support/temp/*
12
/tests/_output/*
23
!/tests/_output/.gitkeep

archive_fusionvm

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ echo "SRCPATH is $SRCPATH"
1919

2020
i=0
2121

22-
while true; do
23-
# Test whether running .vmx files are inside our path.
24-
running=(${(@f)"$(vmrun list | grep "$SRCPATH")"})
22+
# Test whether running .vmx files are inside our path.
23+
running=(${(@f)"$(vmrun list | grep "$SRCPATH")"})
24+
25+
# Save this initial list of .vmx files
26+
vmxlist=($running)
2527

28+
while true; do
2629
echo "Current running VM list is $running"
2730

2831
# If no VMs are running, we can continue.
@@ -40,6 +43,19 @@ while true; do
4043
echo "Suspending $vmx"
4144
vmrun suspend "$vmx"
4245
done
46+
47+
# Refresh running VM list
48+
running=(${(@f)"$(vmrun list | grep "$SRCPATH")"})
49+
done
50+
51+
# Test that every VMX in the list has no lockfile; otherwise quit Fusion
52+
echo "Checking for lockfiles for VM list $vmxlist"
53+
for vmx in $vmxlist; do
54+
echo "Testing lockfile $vmx.lck"
55+
if [ -f "$vmx.lck" ]; then
56+
osascript -e 'tell application "VMware Fusion" to quit'
57+
break
58+
fi
4359
done
4460

4561
# Create a compressed read-only .dmg. HFS+ seems to be smaller than APFS.

tests/_support/mocks/hdiutil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env zsh
22

3-
print -l $@ > $TEMP/hdiutil.calls
3+
print -l $@ >> $TEMP/hdiutil.calls
44

55
exit 0

tests/_support/mocks/osascript

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env zsh
2+
3+
echo "$@" >> $TEMP/osascript.calls
4+
5+
exit 0

tests/archive_fusionvm.zunit

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22

33
# $TEMP is set up in bootstrap
44
@setup {
5-
[ -d $TEMP ] || mkdir $TEMP
5+
[ ! -d $TEMP ] || rm -r $TEMP; mkdir $TEMP
66
[ -f $TEMP/decoy_file ] || touch $TEMP/decoy_file
77
[ -d $TEMP/decoy_dir ] || mkdir $TEMP/decoy_dir
88
}
99

10-
@teardown {
11-
rm -r $TEMP
12-
}
13-
1410
@test 'Exit with error when no arguments are supplied' {
1511
run archive_fusionvm
1612

@@ -114,6 +110,57 @@
114110
fi
115111
}
116112

113+
@test 'osascript executed when lockfile exists' {
114+
vmx="$TEMP/decoy_dir/example vm.vmx"
115+
116+
cat > $TEMP/vmrun_list_1 <<-EOF
117+
$vmx
118+
EOF
119+
120+
touch "$vmx.lck"
121+
122+
run archive_fusionvm $TEMP/decoy_dir $TEMP/out.dmg
123+
124+
if [ -f $TEMP/osascript.calls ]; then
125+
pass
126+
else
127+
fail 'osascript was not called'
128+
fi
129+
}
130+
131+
@test 'osascript is not executed if no lockfiles exist' {
132+
cat > $TEMP/vmrun_list_1 <<-EOF
133+
$TEMP/decoy_dir/example vm.vmx
134+
EOF
135+
136+
run archive_fusionvm $TEMP/decoy_dir $TEMP/out.dmg
137+
138+
if [ -f $TEMP/osascript.calls ]; then
139+
fail 'osascript was called'
140+
else
141+
pass
142+
fi
143+
}
144+
145+
@test 'osascript is executed only once if multiple lockfiles exist' {
146+
vmone="$TEMP/decoy_dir/examplevm one.vmx"
147+
vmtwo="$TEMP/decoy_dir/examplevmtwo.vmx"
148+
149+
cat > $TEMP/vmrun_list_1 <<-EOF
150+
$vmone
151+
$vmtwo
152+
EOF
153+
154+
touch "$vmone.lck"
155+
touch "$vmtwo.lck"
156+
157+
run archive_fusionvm $TEMP/decoy_dir $TEMP/out.dmg
158+
159+
osascriptcalls=(${(@f)"$(<$TEMP/osascript.calls)"})
160+
161+
assert ${#osascriptcalls} equals 1
162+
}
163+
117164
@test 'hdiutil create is executed' {
118165
run archive_fusionvm $TEMP/decoy_dir $TEMP/out.dmg
119166

0 commit comments

Comments
 (0)