From 566482744fba4ca915528bbdccbc0dc1e4740172 Mon Sep 17 00:00:00 2001 From: Jean-Marc MEESSEN Date: Wed, 12 Aug 2020 18:10:23 +0200 Subject: [PATCH] Implement end-to-end tests --- .github/workflows/ci.yml | 6 +++-- Makefile | 5 ++++- test/FLE-sample/sota_wwff.csv | 16 +++++++------- test/bats-scripts/test.bats | 41 +++++++++++++++++++++++++++++++++++ test/commands.md | 3 +++ test/docker-FLEcli.sh | 4 ++-- test/install-bats.sh | 30 +++++++++++++++++++++++++ test/test.sh | 9 ++++---- 8 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 test/bats-scripts/test.bats create mode 100755 test/install-bats.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a463aeb..9f991be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,8 @@ jobs: uses: goreleaser/goreleaser-action@master with: args: release --snapshot --skip-publish --rm-dist - - name: test container - run: docker run on4kjm/flecli:latest version -d + - name: Setup BATS + run: test/install-bats.sh + - name: Run End-To_end testing with the docker container + run: test/bats/bin/bats test/bats-scripts diff --git a/Makefile b/Makefile index 62a03ba..6b9ec52 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ ## GITHUB_ACTIONS is set when running as a Github Action -.PHONY: all lint vet test test-coverage build clean +.PHONY: all lint vet test full-test test-coverage build clean all: build @@ -22,6 +22,9 @@ vet: ## Run go vet test: ## Run unit tests @go test ./... +full-test: build ## Run the full end-to-end tests + @bats test/bats-scripts + test-coverage: ## Run tests with coverage @go test -short -coverprofile cover.out -covermode=atomic ./... @cat cover.out >> coverage.txt diff --git a/test/FLE-sample/sota_wwff.csv b/test/FLE-sample/sota_wwff.csv index 332008a..dde2f6a 100644 --- a/test/FLE-sample/sota_wwff.csv +++ b/test/FLE-sample/sota_wwff.csv @@ -1,8 +1,8 @@ -V2,G3WGV,G/LD-008,24/04/16,1202,7MHz,CW,G4ELZ -V2,G3WGV,G/LD-008,24/04/16,1204,7MHz,CW,G3NOH,,PSE QSL Direct -V2,G3WGV,G/LD-008,24/04/16,1227,144MHz,FM,GW4GTE -V2,G3WGV,G/LD-008,24/04/16,1228,144MHz,FM,GW0TLK/M -V2,G3WGV,G/LD-008,03/06/16,1404,7MHz,CW,GM0AAA -V2,G3WGV,G/LD-008,03/06/16,1405,7MHz,CW,ON4CK/P,ON/ON-018 -V2,G3WGV,G/LD-008,03/06/16,1407,7MHz,CW,DL0DAN/P,DL/AL-044 -V2,G3WGV,G/LD-008,03/06/16,1410,14MHz,CW,YU7LS +V2,G3WGV/P,G/LD-008,24/04/16,1202,7MHz,CW,G4ELZ +V2,G3WGV/P,G/LD-008,24/04/16,1204,7MHz,CW,G3NOH,,PSE QSL Direct +V2,G3WGV/P,G/LD-008,24/04/16,1227,144MHz,FM,GW4GTE +V2,G3WGV/P,G/LD-008,24/04/16,1228,144MHz,FM,GW0TLK/M +V2,G3WGV/P,G/LD-008,03/06/16,1404,7MHz,CW,GM0AAA +V2,G3WGV/P,G/LD-008,03/06/16,1405,7MHz,CW,ON4CK/P,ON/ON-018 +V2,G3WGV/P,G/LD-008,03/06/16,1407,7MHz,CW,DL0DAN/P,DL/AL-044 +V2,G3WGV/P,G/LD-008,03/06/16,1410,14MHz,CW,YU7LS diff --git a/test/bats-scripts/test.bats b/test/bats-scripts/test.bats new file mode 100644 index 0000000..5b82f91 --- /dev/null +++ b/test/bats-scripts/test.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats + +# the file is assumed to be run from the root of the project (test data location) + +@test "Does the version show?" { + output=$(docker run --rm on4kjm/flecli:latest version -d) + echo 'status:' $status + echo 'output:' $output +} + + +@test "Can a simple file be loaded?" { + output=$(test/docker-FLEcli.sh load -i test/data/fle-1.txt) + echo 'status:' $status + echo 'output:' $output +} + + +@test "Can a more complex file be loaded?" { + output=$(test/docker-FLEcli.sh load -i test/data/ON4KJM@ONFF-025920200524.txt) + echo 'status:' $status + echo 'output:' $output +} + +@test "Is the generated SOTA csv equivalent to the canonical one?" { + mkdir -p test/output/temp + output=$(test/docker-FLEcli.sh csv -o -i test/FLE-sample/sota_wwff.txt test/output/temp/sota_wwff.csv) + echo 'status:' $status + echo 'output:' $output + diff test/output/temp/sota_wwff.csv test/FLE-sample/sota_wwff.csv --strip-trailing-cr +} + +@test "Processing a FLE file with no QSO must fail!" { + run test/docker-FLEcli.sh csv -o -i test/data/fle-4-no-qso.txt + [ "$status" -eq 1 ] +} + +@test "Processing a FLE file with parsing errors must fail!" { + run test/docker-FLEcli.sh csv -o -i test/data/fle-5-wrong-call.txt + [ "$status" -eq 1 ] +} \ No newline at end of file diff --git a/test/commands.md b/test/commands.md index 420d5c8..a416768 100644 --- a/test/commands.md +++ b/test/commands.md @@ -6,3 +6,6 @@ * `./FLEcli -i test/data/ON4KJM@ONFF-025920200524.txt --interpolate adif --wwff --overwrite` * `./FLEcli adif -i=test/data/ON4KJM@ONFF-025920200524.txt --interpolate --wwff --overwrite` + + +Install Bats: `brew install bats-core` \ No newline at end of file diff --git a/test/docker-FLEcli.sh b/test/docker-FLEcli.sh index ac2389d..b79f03a 100755 --- a/test/docker-FLEcli.sh +++ b/test/docker-FLEcli.sh @@ -1,4 +1,4 @@ #!/bin/bash -CURRENT_UID = $(id -u):$(id -g) -docker run --rm -ti --user $(CURRENT_UID) -v $(pwd):/FLEcli_data jmmeessen/flecli "$@" +CURRENT_UID=$(id -u):$(id -g) +docker run --rm -t --user ${CURRENT_UID} -v $(pwd):/FLEcli_data on4kjm/flecli:latest "$@" diff --git a/test/install-bats.sh b/test/install-bats.sh new file mode 100755 index 0000000..15e554c --- /dev/null +++ b/test/install-bats.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -eu -o pipefail + +CURRENT_DIR="$(cd "$(dirname "$0")" && pwd -P)" +TMP_DIR=${TMP_DIR:-/tmp} + +## Cleanup +rm -rf "${CURRENT_DIR}/bats" "${TMP_DIR}/bats-core" + +## Prepare +mkdir -p "${CURRENT_DIR}/helpers" + +cat >"${CURRENT_DIR}/helpers/load.bash" <