Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests #2

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: --enable=all --shell=bash
- uses: docker://pipelinecomponents/shellcheck:latest
with:
format: gcc
severity: warning
args: /bin/sh test/bin/ci_shellcheck.sh

yamllint:
name: Yamllint
Expand Down
37 changes: 35 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# https://github.com/particleflux/kcov-bats-circleci-codeclimate

name: Test

Expand All @@ -17,6 +18,38 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- uses: docker://bats/bats:latest
with:
args: test/
submodules: "true"

- name: Download dasel
uses: wei/wget@v1
with:
args: -O test/bin/dasel https://github.com/TomWright/dasel/releases/download/v1.24.1/dasel_linux_amd64
- name: Download yq
uses: wei/wget@v1
with:
args: -O test/bin/yq https://github.com/mikefarah/yq/releases/download/v4.24.5/yq_linux_amd64

- name: Run tests
uses: docker://kcov/kcov:latest
with:
args: /bin/sh test/bin/ci_tests.sh

# https://github.com/particleflux/kcov-bats-circleci-codeclimate/blob/master/.circleci/config.yml
- name: Prepare coverage report
run: |2
sed -r \
's#"bats"#"src"#;s#/github/workspace/##;s#<source>(.+)/</source>#<source>/github/workspace/</source>#' \
"$(ls -1 codecov/bats*/cobertura.xml | head -1)" > coverage.xml
- name: Upload coverage report
uses: codecov/codecov-action@v2
# https://github.com/SimonKagstrom/kcov/blob/master/doc/codecov.md
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
fail_ci_if_error: false

- uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage.xml
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ modules.xml

# End of https://www.toptal.com/developers/gitignore/api/jetbrains+all

.git
codecov/
test/bin/*
!test/bin/ci_*.sh
!test/bin/.gitkeep
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
[submodule "test/test_helper/mocks"]
path = test/test_helper/mocks
url = https://github.com/jasonkarns/bats-mock
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
bats:
@./test/bats/bin/bats test/

bats-cov:
@docker run -it --rm --workdir /github/workspace -v "$PWD":/github/workspace kcov/kcov:latest kcov --include-path src/ codecov/ ./test/bats/bin/bats test/

shellcheck:
@find . -maxdepth 2 -name .git -type d -prune -o -type f \( -name \*.sh -or -name \*.bats \) -print0 | xargs -0 -r -n1 shellcheck --enable=all --severity=warning --shell=bash --color=always
@find . -maxdepth 2 -name .git -type d -prune -o -type f \( -name \*.sh -or -name \*.bats -or -name \*.bash \) -print0 | xargs -0 -r -n1 shellcheck --enable=all --severity=warning --color=always
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Lint](https://github.com/danie1k/rsync-backup/actions/workflows/lint.yml/badge.svg)](https://github.com/danie1k/rsync-backup/actions/workflows/lint.yml)
[![Test](https://github.com/danie1k/rsync-backup/actions/workflows/test.yml/badge.svg)](https://github.com/danie1k/rsync-backup/actions/workflows/test.yml)
[![Code Coverage](https://codecov.io/gh/danie1k/rsync-backup/branch/master/graph/badge.svg?token=07IXMZ0DWO)](https://codecov.io/gh/danie1k/rsync-backup)
[![MIT License](https://img.shields.io/github/license/danie1k/rsync-backup)](https://github.com/danie1k/rsync-backup/blob/master/LICENSE)

# rsync-backup
Expand All @@ -9,8 +10,7 @@ A simple bash script wrapper for the rsync command
## Requirements

- `bash` (or any other bash-compatible shell; `sh`, `dash`, etc. are not supported)
- `dasel` (https://github.com/TomWright/dasel)
- `jq` (https://github.com/stedolan/jq)
- [dasel](https://github.com/TomWright/dasel) or [yq](https://github.com/mikefarah/yq)
- `rsync`
- `screen`
- `envsubst` (optional, a part of `gettext` package)
Expand Down
Loading