linting. test refactoring. initial ci

This commit is contained in:
Lance Vick 2020-11-19 13:40:38 -08:00
parent 3761c62f31
commit 776d594d34
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
8 changed files with 64 additions and 51 deletions

7
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,7 @@
before_script:
- docker info
test:
script:
- make lint
- make test

View File

@ -1,16 +1,16 @@
-----BEGIN PGP SIGNATURE----- -----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEEZ1U/vaRrtxq9LgsLjkeh7DWhVR0FAl+15KAACgkQjkeh7DWh iQIzBAABCgAdFiEEZ1U/vaRrtxq9LgsLjkeh7DWhVR0FAl+25jgACgkQjkeh7DWh
VR1jcA//bzlmfj/rr3l/J1jbroHVLSROqIi/HtK0b6hUccVkk7cwczbaDOvHIBva VR2qOA//fFUsl8qE3L5+5VpUX2eIJ9+fdzo+4cSgRojwZOWt4QbjfcWYGRIotyqF
aqiZzgRSvklVzxXFBdEtcJXV1DhWOYv+jokiyacPbnlcspoSqPX4GpH88ARKWo+p QkX2nyU1vesApQfDSDsvnC7qZq2Rm/0CXYr3+QXZ1tMT030oQYLkxG+gNQjVYqWU
0T4ASS0aEvvALebtjVIoQuVLIQECqSqmuupnCsmALf62TXucU5a/Nzk/yGJxpdN/ o3jPkGjZg7u8DzGngp33wgsJ6l5bP16HbIxAdslAwtccq2daq8pU9w238H8dBcyx
O12DTDU8ey4rG80Ycn6l+yuWi85JKcrAy9VIUq8b+1rV+1jRpcYJONNirIkZBUhs WWzW7PrYae/LKAu7lMKpTEohmQ9RbXqPDoGaMks+FqZaOZvRhvTyiYFkyTMasVQM
Txipc4WxEyZ9Njwb9J6lK1LyilZ4cABjW/cpVFFh4EtWUisnkH4qNQkmw0evbAGW 7gf9P5mOMyGX7GvCzkdkEUUuT1T9IcJNa2vDZP5Thyr+t+W5ABWy+uvS1G5YDBGX
gLrhrSMrkXxYOJQqtFKsKPYsF0hjDFdnSImbkD12Nm2TUetkdueLfKmDi3jDgeNY GAPAUQ2a9CpuOGwSsxlrwiXcXuPly2FqspIewAwB/jCyRcrpUHEAK4a/WiNyjl0X
lJRUgbgjnkNWJ28ukdF7f4F6Z+ECkk5NCjyqmQcsX1T4HLXLrwUbTA/I3y7bG7KN oBRskNSVKFm7K33eDQC7yMOYHraIsu8/swuaE+7joitmhQGlxXq6+fQ53sF6N8L6
0x97ILMXvcm2wzVROEOpqRoUxRgYUbwg3Bj8OPYshHJqnL3SH17Va+ACLfUxfcrC YOQH5sHvrf9RO+sDsctYEBzBCUV2MZgdoVRyOhOLyeyqMUsQ1rnCPQeqU6GCHd9m
FtkM2EWkvKT5M+HFSHdeFj5RcV4JqYsFLdAdCH+d4hFvDdW3qe2oObUUd2ArAbw5 yrmECNaZ7fKhh37mihmBNjJzsefkXHWFgaDRIOe8MqOxQNFWjFUYl/hF4ek9bd3b
e9XMnc86PS5tczH/CU/+n8heLIHjT6CvlkrLowQLPBWi8t58qtEk6qnWnb2iuEeD 2j6LfZ/OwrJvtywYgxPvaBc/uWG8X+2TBgxXG0tvbybIHMa9nnFQoV2ykuF7ET+Z
VlEYwIZpVwybdt1q6yxMyYettltIfcQFzgF53WXYoQUgGliqneI= 4YHJkppqy7pAPwzuNkPI4/GZavABCqWzCaty5ZVMnoUpnd6nGec=
=QAAB =/hRR
-----END PGP SIGNATURE----- -----END PGP SIGNATURE-----

View File

@ -1,7 +1,8 @@
64263feac7b00952e9ec3b6c1fd11316faa58ff673c6bd085fac9f6f8d8389f6 .gitignore 64263feac7b00952e9ec3b6c1fd11316faa58ff673c6bd085fac9f6f8d8389f6 .gitignore
71be2fa2aadd9c8f77355ed17e4e246ca07d38e0e9d1f4324181c89695e82eb4 Makefile 66a3b8bfb76f689fc4ab7bd95907b29c17c704c075c00c6cc6382e424dccd6bb .gitlab-ci.yml
d26196a972cda50b2ce735fcce3f64fa2634f85822a18f07cd7ab42aa24bec0e Makefile
f19d267e4aa6bf82d5416891697a2a81a574efdddecf5c54e3a8a77c207013fa README.md f19d267e4aa6bf82d5416891697a2a81a574efdddecf5c54e3a8a77c207013fa README.md
bf3492ca7625d9ac199678cf2828253e5968a87c5c444ec92e2a90ed1cbbac49 sig b8fe3398ecd3992d190fa5f0c475a8ae424c4500407cd5b8e568b048d4844b3f sig
f2277f49854ad048ab66f890c01d43476aada9ee2aca7a688d4ea9fd6c0f8d2a test/Dockerfile 655df07f3827e7055d0c6aa21a0a4907957a34a2b8a1e9131225c537e448e2e3 test/Dockerfile
ede387dce19cb471142b0bd914d4f7f99af26624080b92cb18328ece2cdfb191 test/test.bats 55250be3c8f25dcbe68a73e8de8c8a94d8ceb0354c7f955519373d9c963903dd test/test.bats
c9c68b5bd5c4a62818d36731eb5a0c359474837e0e4cfe19d6ac48d15d920002 test/test_helper.bash c95e072f0917531257c069516fc1bf08fd98e5c5f3958f5353a219cb5b70fd38 test/test_helper.bash

View File

@ -1,4 +1,4 @@
.PHONY: .PHONY: test
test: test-image test: test-image
docker run \ docker run \
--rm \ --rm \
@ -7,6 +7,15 @@ test: test-image
local/sig-test \ local/sig-test \
bats sig/test/test.bats bats sig/test/test.bats
.PHONY: lint
lint: test-image
docker run \
--rm \
--interactive \
--volume $(PWD)/:/home/test/sig \
local/sig-test \
shellcheck sig/sig
.PHONY: test-image .PHONY: test-image
test-image: test-image:
docker build \ docker build \
@ -14,8 +23,8 @@ test-image:
--file $(PWD)/test/Dockerfile \ --file $(PWD)/test/Dockerfile \
$(PWD) $(PWD)
.PHONY: .PHONY: test-shell
test-shell: test-shell test-shell: test-image
docker run \ docker run \
--rm \ --rm \
--interactive \ --interactive \

2
sig
View File

@ -227,7 +227,7 @@ verify_detached() {
for sig_filename in "${filename%.*}".*.asc; do for sig_filename in "${filename%.*}".*.asc; do
gpg --verify "${sig_filename}" "${filename}" >/dev/null 2>&1 || { gpg --verify "${sig_filename}" "${filename}" >/dev/null 2>&1 || {
echo "Invalid signature: ${sig_filename}"; echo "Invalid detached signature: ${sig_filename}";
exit 1; exit 1;
} }
file_fp=$( get_file_fp "${sig_filename}" ) file_fp=$( get_file_fp "${sig_filename}" )

View File

@ -1,10 +1,10 @@
FROM debian:buster FROM debian:buster
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --force-yes bats git gnupg openssl && \ apt-get install -y --force-yes sudo bats git gnupg openssl shellcheck
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN useradd -m test RUN useradd -m test -G sudo -s /bin/bash
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER test USER test

View File

@ -19,38 +19,23 @@ load test_helper
} }
@test "Outputs advice to install missing openssl" { @test "Outputs advice to install missing openssl" {
mask_command openssl sudo rm /usr/bin/openssl
run sig version run sig version
echo "${output}" | grep "apt install openssl" echo "${output}" | grep "apt install openssl"
} }
@test "Outputs advice to install missing gpg" { @test "Outputs advice to install missing gpg" {
mask_command gpg sudo rm /usr/bin/gpg
run sig version run sig version
echo "${output}" | grep "apt install gnupg" echo "${output}" | grep "apt install gnupg"
} }
@test "Outputs advice to install missing getopt" { @test "Outputs advice to install missing getopt" {
mask_command getopt sudo rm /usr/bin/getopt
run sig version run sig version
echo "${output}" | grep "apt install getopt" 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" { @test "Can generate manifest for git repo" {
set_identity "user1" set_identity "user1"
echo "test string" > somefile echo "test string" > somefile
@ -63,3 +48,18 @@ load test_helper
run grep 37d2046a395cbfc .sig/manifest.txt run grep 37d2046a395cbfc .sig/manifest.txt
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "Can generate manifest for folder with git not installed" {
sudo rm /usr/bin/git
echo "test string" > somefile
sig manifest
run grep 37d2046a395cbfc .sig/manifest.txt
[ "$status" -eq 0 ]
}
@test "Can generate manifest for folder with git installed" {
echo "test string" > somefile
sig manifest
run grep 37d2046a395cbfc .sig/manifest.txt
[ "$status" -eq 0 ]
}

View File

@ -1,6 +1,10 @@
#!/bin/bash #!/bin/bash
setup(){ setup(){
test -f /usr/bin/git || sudo apt install --reinstall -y git
test -f /usr/bin/getopt || sudo apt install --reinstall -y util-linux
test -f /usr/bin/gpg || sudo apt install --reinstall -y gpg
test -f /usr/bin/openssl || sudo apt install --reinstall -y openssl
bin_dir=/tmp/bin bin_dir=/tmp/bin
temp_dir=$(mktemp -d -t test-XXXXXXXXXX) temp_dir=$(mktemp -d -t test-XXXXXXXXXX)
mkdir -p /tmp/bin mkdir -p /tmp/bin
@ -19,11 +23,3 @@ set_identity(){
git config --global user.email "${name}@example.com" git config --global user.email "${name}@example.com"
git config --global user.name "${name}" 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}"
}