Skip to content

Commit 3ca3774

Browse files
authored
Add more tests for start_ursim.sh (#305)
This should fully validate input argument parsing.
1 parent c832d36 commit 3ca3774

File tree

2 files changed

+145
-2
lines changed

2 files changed

+145
-2
lines changed

scripts/start_ursim.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ parse_arguments(){
323323
\?) # invalid option
324324
echo "Error: Invalid option"
325325
help
326-
exit;;
326+
exit 1
327327
esac
328328
done
329329
}
@@ -442,7 +442,7 @@ main() {
442442

443443
if [ "$TEST_RUN" = true ]; then
444444
echo "$docker_cmd" | tr -s ' '
445-
exit
445+
exit 0
446446
fi
447447
$docker_cmd || exit 2
448448

tests/test_start_ursim.bats

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,146 @@ setup() {
316316
echo "Robot model is: $ROBOT_MODEL"
317317
[ "$ROBOT_MODEL" = "UR30" ]
318318
}
319+
320+
@test "help_prints_fine" {
321+
run main -h
322+
[ $status -eq 0 ]
323+
}
324+
325+
@test "setting_urcap_storage" {
326+
run main -t
327+
echo "$output"
328+
[ $status -eq 0 ]
329+
urcap_mount=$(echo "$output" | tail -n1 | grep -Po "\-v\ [\/\w+\.\-]+:\/urcaps" | cut -d ':' -f1 | cut -d " " -f 2)
330+
[ "$urcap_mount" = "$HOME/.ursim/e-series/urcaps" ]
331+
332+
run main -t -v 3.14.3
333+
echo "$output"
334+
[ $status -eq 0 ]
335+
urcap_mount=$(echo "$output" | tail -n1 | grep -Po "\-v\ [\/\w+\.\-]+:\/urcaps" | cut -d ':' -f1 | cut -d " " -f 2)
336+
[ "$urcap_mount" = "$HOME/.ursim/cb3/urcaps" ]
337+
338+
target_dir=$(mktemp -d)
339+
run main -u "$target_dir" -t
340+
echo "$output"
341+
[ $status -eq 0 ]
342+
urcap_mount=$(echo "$output" | tail -n1 | grep -Po "\-v\ [\/\w+\.\-]+:\/urcaps" | cut -d ':' -f1 | cut -d " " -f 2)
343+
[ "$urcap_mount" = "$target_dir" ]
344+
345+
}
346+
347+
@test "setting_program_storage" {
348+
run main -t
349+
echo "$output"
350+
[ $status -eq 0 ]
351+
program_mount=$(echo "$output" | tail -n1 | grep -Po "\-v\ [\/\w+\.\-]+:\/ursim\/programs" | cut -d ':' -f1 | cut -d " " -f 2)
352+
[ "$program_mount" = "$HOME/.ursim/e-series/ur5e/programs" ]
353+
354+
run main -t -v 3.14.3
355+
echo "$output"
356+
[ $status -eq 0 ]
357+
program_mount=$(echo "$output" | tail -n1 | grep -Po "\-v\ [\/\w+\.\-]+:\/ursim\/programs" | cut -d ':' -f1 | cut -d " " -f 2)
358+
[ "$program_mount" = "$HOME/.ursim/cb3/ur5/programs" ]
359+
360+
run main -t -v 10.7.0
361+
echo "$output"
362+
[ $status -eq 0 ]
363+
program_mount=$(echo "$output" | tail -n1 | grep -Po "\-v\ [\/\w+\.\-]+:\/ur\/bin\/backend\/applications" | cut -d ':' -f1 | cut -d " " -f 2)
364+
[ "$program_mount" = "$HOME/.ursim/polyscopex/ur5e/programs" ]
365+
366+
target_dir=$(mktemp -d)
367+
run main -p "$target_dir" -t
368+
echo "$output"
369+
[ $status -eq 0 ]
370+
program_mount=$(echo "$output" | tail -n1 | grep -Po "\-v\ [\/\w+\.\-]+:\/ursim\/programs" | cut -d ':' -f1 | cut -d " " -f 2)
371+
[ "$program_mount" = "$target_dir" ]
372+
}
373+
374+
@test "setting_ip_addresss" {
375+
run main -t -i 123.123.123.123
376+
echo "$output"
377+
[ $status -eq 0 ]
378+
ip_address=$(echo "$output" | tail -n1 | grep -o -E "\-\-ip ([0-9]+\.?)+" | cut -d " " -f2)
379+
[ "$ip_address" = "123.123.123.123" ]
380+
}
381+
382+
@test "default_port_forwarding_cb3" {
383+
run main -t -v 3.14.3
384+
echo "$output"
385+
[ $status -eq 0 ]
386+
port_forwarding=$(echo "$output" | tail -n -1 | grep -Eo "(\-p\s*[0-9]+(\-[0-9]+)?:[0-9]+(\-[0-9]+)?\s*)+" | awk '{$1=$1};1')
387+
[ "$port_forwarding" = "$PORT_FORWARDING_WITH_DASHBOARD" ]
388+
}
389+
390+
@test "default_port_forwarding_e-series" {
391+
run main -t -v 5.21.0
392+
echo "$output"
393+
[ $status -eq 0 ]
394+
port_forwarding=$(echo "$output" | tail -n -1 | grep -Eo "(\-p\s*[0-9]+(\-[0-9]+)?:[0-9]+(\-[0-9]+)?\s+)+" | awk '{$1=$1};1')
395+
[ "$port_forwarding" = "$PORT_FORWARDING_WITH_DASHBOARD" ]
396+
}
397+
398+
@test "default_port_forwarding_polyscopex" {
399+
run main -t -v 10.7.0
400+
echo "$output"
401+
[ $status -eq 0 ]
402+
port_forwarding=$(echo "$output" | tail -n -1 | grep -Eo "(\-p\s*[0-9]+(\-[0-9]+)?:[0-9]+(\-[0-9]+)?\s*)+" | awk '{$1=$1};1')
403+
[ "$port_forwarding" = "$PORT_FORWARDING_WITHOUT_DASHBOARD" ]
404+
}
405+
406+
@test "setting_port_forwarding" {
407+
run main -t -f "-p 1234:1234 -p 50001-50004:60001-60004"
408+
echo "$output"
409+
[ $status -eq 0 ]
410+
port_forwarding=$(echo "$output" | tail -n -1 | grep -Eo "(\-p\s*[0-9]+(\-[0-9]+)?:[0-9]+(\-[0-9]+)?\s*)+" | awk '{$1=$1};1')
411+
[ "$port_forwarding" = "-p 1234:1234 -p 50001-50004:60001-60004" ]
412+
}
413+
414+
@test "default_container_name" {
415+
run main -t
416+
echo "$output"
417+
[ $status -eq 0 ]
418+
container_name=$(echo "$output" | tail -n -1 | grep -o -E "\-\-name\s\w+" | cut -d " " -f2)
419+
[ "$container_name" = "ursim" ]
420+
}
421+
422+
@test "setting_container_name_cb3" {
423+
run main -t -n "ursim_test" -v 3.14.3
424+
echo "$output"
425+
[ $status -eq 0 ]
426+
container_name=$(echo "$output" | tail -n -1 | grep -o -E "\-\-name\s\w+" | cut -d " " -f2)
427+
[ "$container_name" = "ursim_test" ]
428+
}
429+
430+
@test "setting_container_name_e-series" {
431+
run main -t -n "ursim_test" -v 5.21.0
432+
echo "$output"
433+
[ $status -eq 0 ]
434+
container_name=$(echo "$output" | tail -n -1 | grep -o -E "\-\-name\s\w+" | cut -d " " -f2)
435+
[ "$container_name" = "ursim_test" ]
436+
}
437+
438+
@test "setting_container_name_polyscopex" {
439+
run main -t -n "ursim_test" -v 10.7.0
440+
echo "$output"
441+
[ $status -eq 0 ]
442+
container_name=$(echo "$output" | tail -n -1 | grep -o -E "\-\-name\s\w+" | cut -d " " -f2)
443+
[ "$container_name" = "ursim_test" ]
444+
}
445+
446+
@test "catch_unknown_parameters" {
447+
run main -t -x
448+
echo "$output"
449+
[ $status -eq 1 ]
450+
}
451+
452+
@test "not_detached_by_default" {
453+
test_input_handling
454+
[ "$DETACHED" = "false" ]
455+
}
456+
457+
@test "setting_detached_argument" {
458+
test_input_handling -d
459+
[ "$DETACHED" = "true" ]
460+
}
461+

0 commit comments

Comments
 (0)