Skip to content

Commit ad47f9f

Browse files
committed
Add tests to CLI
1 parent be31975 commit ad47f9f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

test_cli.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# See https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
4+
set -o errexit -o errtrace -o nounset -o pipefail
5+
6+
MASTER_SECRET='bb54aac4b89dc868ba37d9cc21b2cece'
7+
MNEMONICS_2OF3=(
8+
'shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed'
9+
'shadow pistol academic acid actress prayer class unknown daughter sweater depict flip twice unkind craft early superior advocate guest smoking'
10+
)
11+
12+
echo_bold() {
13+
local bold normal
14+
bold="$(tput bold)"
15+
normal="$(tput sgr0)"
16+
echo "${bold}${*}${normal}"
17+
}
18+
19+
echo_error() {
20+
local error normal
21+
# Red color
22+
error="$(tput setaf 1)"
23+
normal="$(tput sgr0)"
24+
echo >&2 "${error}${*}${normal}"
25+
}
26+
27+
run_tests() {
28+
if ! command -v shamir > /dev/null; then
29+
echo 'shamir executable not found'
30+
exit 1
31+
fi
32+
echo_bold 'Starting CLI tests for runtime errors (NOT testing correctness)'
33+
local status=0
34+
echo_bold 'Testing create 2of3...'
35+
(shamir create 2of4 > /dev/null) || status=1
36+
echo_bold 'Testing create 2of3 with user provided secret...'
37+
(shamir create 2of4 --master-secret "${MASTER_SECRET}" > /dev/null) || status=1
38+
echo_bold 'Testing create 2of3 with user provided secret and passphrase...'
39+
(shamir create 2of4 --master-secret "${MASTER_SECRET}" --passphrase 'TREZOR' > /dev/null) || status=1
40+
echo_bold 'Testing recovery...'
41+
(printf '%s\n' "${MNEMONICS_2OF3[@]}" | shamir recover > /dev/null) || status=1
42+
return "${status}"
43+
}
44+
45+
main() {
46+
if ! run_tests; then
47+
echo_error 'Some of the tests failed! see above for the failed tests.'
48+
exit 1
49+
fi
50+
echo_bold 'All tests passed!'
51+
}
52+
53+
main "$@"

0 commit comments

Comments
 (0)