Skip to content

Commit

Permalink
Use bats-core instead of bats
Browse files Browse the repository at this point in the history
There is a separate Docker worker that allows running Bats tests based
on version 1.2.0 of `bats-core` project. This modification allows
receiving updates to the test runner.

All testing procedure is reworked in a way that `workflows` file is
responsible for running Docker workers for testing while scripts,
located at `.workflows` directory, just run the needed workflows without
pointing to an environment.

`tests/git-elegant.bats` was updated as in Bash 3.x (which is used in
the Bats worker) is not possible to get the last element of the array.
So, `show-commands` in the tests is replaced with `prune-repository` as
the last command produces the same amount of lines comparing to the fact
that adding or removing of command will affect the output of
`show-commands`.

#135
  • Loading branch information
extsoft committed Jun 10, 2020
1 parent 5b75404 commit 23944d2
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 140 deletions.
12 changes: 0 additions & 12 deletions .workflows/bats-pipeline.bash

This file was deleted.

15 changes: 15 additions & 0 deletions .workflows/bats/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG bashversion=3.2.57
FROM bash:${bashversion}
LABEL maintainer="Dmytro Serdiuk <[email protected]>" \
description="The image serves the environment for the testing of Elegant Git."
VOLUME /elegant-git
WORKDIR /elegant-git
ENV EG_ENABLE_TESTING true
ARG gitversion=2.26.2
RUN apk add --no-cache git~=${gitversion}
ARG batsversion=v1.2.0
RUN git clone --branch ${batsversion} --single-branch --depth 1 https://github.com/bats-core/bats-core.git; \
cd bats-core && ./install.sh /usr/local && cd - && rm -r bats-core
COPY bats-workflows.bash /bats-workflows.bash
ENTRYPOINT [ "/bats-workflows.bash" ]
CMD ["help"]
38 changes: 38 additions & 0 deletions .workflows/bats/bats-workflows.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -e
# Runs bats tests
# usage: ./script [command name]
if [[ -f version ]]; then
rm -v version
fi

all_tests() {
exec bats --tap --recursive tests
}

some_tests() {
exec bats --tap $(find tests -type f -name "*${1}*")
}

usage() {
cat <<MESSAGE
usage: ${BASH_SOURCE[0]} <command>
Available commands:
help prints this message
all_tests runs all Bats tests
some_tests runs Bats tests matchinh a pattern
MESSAGE
}

main() {
case ${1} in
all_tests) all_tests ;;
some_tests) shift; some_tests "${@}" ;;
help) usage ;;
*) "${@}" ;;
esac
}

main "${@}"
55 changes: 0 additions & 55 deletions .workflows/ci-pipeline.bash

This file was deleted.

53 changes: 53 additions & 0 deletions .workflows/installation-workflows.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# This script is destructive! That's why it will work only if a specific variable is set.
# It's recommended to run it within a docker container only.
# Usage:
# ./installation-workflows.bash runs quality pipeline
# ./installation-workflows.bash prints tooling version
set -e

install() {
echo "Installation...."
git config --global user.name "Elegant Git"
git config --global user.email [email protected]
git config --global core.editor vi
git config --global elegant-git.acquired true
./install.bash /usr/local src
}

smoke-tests() {
echo "'Unknown command' testing..."
git elegant unknown-command | grep "Unknown command: git elegant unknown-command"
echo "Check installation of version's file..."
git elegant --version || exit 1
}

check-env() {
if [[ -z ${EG_ENABLE_TESTING} ]]; then
echo "Testing is disabled! Looks like the environment is not ready..."
exit 1
fi
}

usage() {
cat <<MESSAGE
usage: ${BASH_SOURCE[0]} <command>
Available commands:
help prints this message
install runs the installation process
smoke-tests runs smoke tests of the installation
MESSAGE
}

main() {
case $1 in
install) check-env && install ;;
smoke-tests) check-env && smoke-tests ;;
help) usage ;;
*) echo "Available commands: --version or testing"; exit 1 ;;
esac
}

main "$@"
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Run `unset GED` to switch debug off.

### Testing procedure
A testing procedure consists of 3 steps:
1. unit testing using [bats](https://github.com/sstephenson/bats)
1. unit testing using [bats-core](https://github.com/bats-core/bats-core)
2. installation testing
3. validation of documentation correctness

Expand Down
46 changes: 23 additions & 23 deletions tests/git-elegant.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,49 +43,49 @@ teardown(){

@test "'git elegant': a version is displayed correctly" {
check git-elegant --version
[[ ${lines[@]} =~ "/eg/tests/../libexec/../version" ]]
[[ ${lines[@]} =~ "/elegant-git/tests/../libexec/../version" ]]
}

@test "'git elegant': workflows are loaded correctly when a command is executed from root directory" {
repo "mkdir -p .workflows .git/.workflows"
repo "echo echo ahead git > .git/.workflows/show-commands-ahead"
repo "echo echo ahead no > .workflows/show-commands-ahead"
repo "echo echo after git > .git/.workflows/show-commands-after"
repo "echo echo after no > .workflows/show-commands-after"
repo "echo echo ahead git > .git/.workflows/prune-repository-ahead"
repo "echo echo ahead no > .workflows/prune-repository-ahead"
repo "echo echo after git > .git/.workflows/prune-repository-after"
repo "echo echo after no > .workflows/prune-repository-after"
repo "chmod +x .git/.workflows/* .workflows/*"
repo "ls -lah .git/.workflows/* .workflows/*"
check git-elegant show-commands
check git-elegant prune-repository
[[ ${status} -eq 0 ]]
[[ ${lines[0]} =~ ".git/.workflows/show-commands-ahead" ]]
[[ ${lines[0]} =~ ".git/.workflows/prune-repository-ahead" ]]
[[ ${lines[1]} == "ahead git" ]]
[[ ${lines[2]} =~ ".workflows/show-commands-ahead" ]]
[[ ${lines[2]} =~ ".workflows/prune-repository-ahead" ]]
[[ ${lines[3]} == "ahead no" ]]
[[ ${lines[-4]} =~ ".git/.workflows/show-commands-after" ]]
[[ ${lines[-3]} == "after git" ]]
[[ ${lines[-2]} =~ ".workflows/show-commands-after" ]]
[[ ${lines[-1]} == "after no" ]]
[[ ${lines[6]} =~ ".git/.workflows/prune-repository-after" ]]
[[ ${lines[7]} == "after git" ]]
[[ ${lines[8]} =~ ".workflows/prune-repository-after" ]]
[[ ${lines[9]} == "after no" ]]
}

@test "'git elegant': workflows are loaded correctly when a command is executed from non-root directory" {
repo mkdir -p .workflows .git/.workflows
repo "echo echo ahead git > .git/.workflows/show-commands-ahead"
repo "echo echo ahead no > .workflows/show-commands-ahead"
repo "echo echo after git > .git/.workflows/show-commands-after"
repo "echo echo after no > .workflows/show-commands-after"
repo "echo echo ahead git > .git/.workflows/prune-repository-ahead"
repo "echo echo ahead no > .workflows/prune-repository-ahead"
repo "echo echo after git > .git/.workflows/prune-repository-after"
repo "echo echo after no > .workflows/prune-repository-after"
repo "chmod +x .git/.workflows/* .workflows/*"
repo "ls -lah .git/.workflows/* .workflows/*"
repo "mkdir -p some/path"
repo "cd some/path"
check git-elegant show-commands
check git-elegant prune-repository
[[ ${status} -eq 0 ]]
[[ ${lines[0]} =~ ".git/.workflows/show-commands-ahead" ]]
[[ ${lines[0]} =~ ".git/.workflows/prune-repository-ahead" ]]
[[ ${lines[1]} == "ahead git" ]]
[[ ${lines[2]} =~ ".workflows/show-commands-ahead" ]]
[[ ${lines[2]} =~ ".workflows/prune-repository-ahead" ]]
[[ ${lines[3]} == "ahead no" ]]
[[ ${lines[-4]} =~ ".git/.workflows/show-commands-after" ]]
[[ ${lines[-3]} == "after git" ]]
[[ ${lines[-2]} =~ ".workflows/show-commands-after" ]]
[[ ${lines[-1]} == "after no" ]]
[[ ${lines[6]} =~ ".git/.workflows/prune-repository-after" ]]
[[ ${lines[7]} == "after git" ]]
[[ ${lines[8]} =~ ".workflows/prune-repository-after" ]]
[[ ${lines[9]} == "after no" ]]
}

@test "'git elegant': workflows are ignored if --no-workflows is set before a command" {
Expand Down
Loading

0 comments on commit 23944d2

Please sign in to comment.