add tests, including some failing tests that catch edge cases I need to fix

This commit is contained in:
Lance Vick 2020-11-18 19:22:08 -08:00
parent eaafaa376c
commit 3761c62f31
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
6 changed files with 91 additions and 27 deletions

View File

@ -1,16 +1,16 @@
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEEZ1U/vaRrtxq9LgsLjkeh7DWhVR0FAl+1wcEACgkQjkeh7DWh
VR37fA/+Kz9RCCUk/IMawjMO1mVXrM5Lsq4fEXgs16yYlzj7uqyYb8B+R+l3z8ZU
VQd8xiphjhq6XY6jrThnjcPu0SRrl9x3hTnofeB4w5cTmu5jo9FiP1BvTWiAVri7
45KZ8uJv3PAbdTx+NiOZiGSSkOkn8WV5sYwPJbJHS7CrJk8yZzbHyNcL5UDlzi1R
uSqtG0hQk+NY3CrAsGEGlX1KqXowjRkIUb9IGIYli61NuqCiDKBZBlB4J/i1J2DU
GJbtwkbb1Io4csYFwZNDBFrMZG7pTpWYr5u1JNgL1BROVbAU8wjKOASaR168mbOm
2CLXt9hOXU0PBCziVFgI1YW1gh3Eqtqey9LSbH1UsfU/4aQ4uByq5fjyiCGs0cet
HuhcHVJOZsCyzTUJoqjQ5grGW3p95gMJxFFznQ+ryjY6r2u5ZNnrp9WnMy3Iquoz
nKwZywRCO2ACO/5SqBYgJeWc17WA7WKi1khMkuP6G+oi3YFN3xcDIU6dcRgb1tsl
xLOavB07I/8AppEyHq4yJ2rgUir+WEK6UoOkjisj5qm243ZBZ8gjSBYYIupv7h6M
TsWnzUhv+OKlYrc3WdAMSI+tln+vGK7KRjksmgH349um8zG9WcwR5OIn5IaMxzbg
MO9AHYeVYuaphELTiufE4aKMgnP3gvLavrDANxhd884ZpcNp5E8=
=O65j
iQIzBAABCgAdFiEEZ1U/vaRrtxq9LgsLjkeh7DWhVR0FAl+15KAACgkQjkeh7DWh
VR1jcA//bzlmfj/rr3l/J1jbroHVLSROqIi/HtK0b6hUccVkk7cwczbaDOvHIBva
aqiZzgRSvklVzxXFBdEtcJXV1DhWOYv+jokiyacPbnlcspoSqPX4GpH88ARKWo+p
0T4ASS0aEvvALebtjVIoQuVLIQECqSqmuupnCsmALf62TXucU5a/Nzk/yGJxpdN/
O12DTDU8ey4rG80Ycn6l+yuWi85JKcrAy9VIUq8b+1rV+1jRpcYJONNirIkZBUhs
Txipc4WxEyZ9Njwb9J6lK1LyilZ4cABjW/cpVFFh4EtWUisnkH4qNQkmw0evbAGW
gLrhrSMrkXxYOJQqtFKsKPYsF0hjDFdnSImbkD12Nm2TUetkdueLfKmDi3jDgeNY
lJRUgbgjnkNWJ28ukdF7f4F6Z+ECkk5NCjyqmQcsX1T4HLXLrwUbTA/I3y7bG7KN
0x97ILMXvcm2wzVROEOpqRoUxRgYUbwg3Bj8OPYshHJqnL3SH17Va+ACLfUxfcrC
FtkM2EWkvKT5M+HFSHdeFj5RcV4JqYsFLdAdCH+d4hFvDdW3qe2oObUUd2ArAbw5
e9XMnc86PS5tczH/CU/+n8heLIHjT6CvlkrLowQLPBWi8t58qtEk6qnWnb2iuEeD
VlEYwIZpVwybdt1q6yxMyYettltIfcQFzgF53WXYoQUgGliqneI=
=QAAB
-----END PGP SIGNATURE-----

View File

@ -1,7 +1,7 @@
64263feac7b00952e9ec3b6c1fd11316faa58ff673c6bd085fac9f6f8d8389f6 .gitignore
6be935105cf23a76df12868caf56e52f95f1b9fc64645b1079eb7a07cc8682a3 Makefile
71be2fa2aadd9c8f77355ed17e4e246ca07d38e0e9d1f4324181c89695e82eb4 Makefile
f19d267e4aa6bf82d5416891697a2a81a574efdddecf5c54e3a8a77c207013fa README.md
bf3492ca7625d9ac199678cf2828253e5968a87c5c444ec92e2a90ed1cbbac49 sig
fe58cbd410c8fe1c3086447b6a0187d6f42b536ab34347e523373a9e92a9421b test/Dockerfile
1f2cfe885b4134129f5d67669e6f6f432194fff787117f5cb4297fddb58d6e16 test/test.bats
4e87988899634e85354372f18b26d778a5f60f921ebee1b8c543477ce9787aa3 test/test_helper.bash
f2277f49854ad048ab66f890c01d43476aada9ee2aca7a688d4ea9fd6c0f8d2a test/Dockerfile
ede387dce19cb471142b0bd914d4f7f99af26624080b92cb18328ece2cdfb191 test/test.bats
c9c68b5bd5c4a62818d36731eb5a0c359474837e0e4cfe19d6ac48d15d920002 test/test_helper.bash

View File

@ -3,9 +3,9 @@ test: test-image
docker run \
--rm \
--interactive \
--volume $(PWD)/:/home/test/ \
--volume $(PWD)/:/home/test/sig \
local/sig-test \
bats test/test.bats
bats sig/test/test.bats
.PHONY: test-image
test-image:
@ -19,6 +19,6 @@ test-shell: test-shell
docker run \
--rm \
--interactive \
--volume $(PWD)/:/home/test/ \
--volume $(PWD)/:/home/test/sig \
local/sig-test \
bash

View File

@ -1,7 +1,7 @@
FROM debian:buster
RUN apt-get update && \
apt-get install -y --force-yes bats gnupg openssl && \
apt-get install -y --force-yes bats git gnupg openssl && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN useradd -m test

View File

@ -1,20 +1,65 @@
load test_helper
@test "Outputs help if run without arguments" {
run ./sig
run sig
[ "$status" -eq 0 ]
echo "${output}" | grep "simple multisig trust toolchain"
}
@test "Outputs help if run with help" {
run ./sig help
run sig help
[ "$status" -eq 0 ]
echo "${output}" | grep "simple multisig trust toolchain"
}
@test "Outputs version if run with version" {
run ./sig version
run sig version
[ "$status" -eq 0 ]
echo "${output}" | grep "v0.0.1"
}
@test "Outputs advice to install missing openssl" {
mask_command openssl
run sig version
echo "${output}" | grep "apt install openssl"
}
@test "Outputs advice to install missing gpg" {
mask_command gpg
run sig version
echo "${output}" | grep "apt install gnupg"
}
@test "Outputs advice to install missing getopt" {
mask_command getopt
run sig version
echo "${output}" | grep "apt install getopt"
}
@test "Can generate manifest for folder with git installed" {
echo "test string" > somefile
sig manifest
run grep 37d2046a395cbfc .sig/manifest.txt
[ "$status" -eq 0 ]
}
@test "Can generate manifest for folder with git not installed" {
mask_command git
echo "test string" > somefile
sig manifest
run grep 37d2046a395cbfc .sig/manifest.txt
[ "$status" -eq 0 ]
}
@test "Can generate manifest for git repo" {
set_identity "user1"
echo "test string" > somefile
git init
git add .
git commit -m "initial commit"
sig manifest
run grep -q "1" <(wc -l .sig/manifest.txt)
[ "$status" -eq 0 ]
run grep 37d2046a395cbfc .sig/manifest.txt
[ "$status" -eq 0 ]
}

View File

@ -1,10 +1,29 @@
#!/bin/bash
setup(){
echo "running setup"
bin_dir=/tmp/bin
temp_dir=$(mktemp -d -t test-XXXXXXXXXX)
mkdir -p /tmp/bin
cp /home/test/sig/sig /tmp/bin/sig
export PATH=${bin_dir}:${PATH}
cd "$temp_dir" || return 1
}
teardown(){
echo "running teardown"
rm -rf "$temp_dir"
}
set_identity(){
local -r name="${1?}"
echo "set key to $name"
git config --global user.email "${name}@example.com"
git config --global user.name "${name}"
}
mask_command(){
local -r command="${1?}"
echo "echo >&2 \"bash: ${command}: command not found\" && exit 127" \
> "${command}"
chmod +x "${command}"
export PATH="$PWD:$PATH" "${command}"
}