Skip to content

Commit 2f19967

Browse files
committed
use docker for testing
1 parent f8caacf commit 2f19967

28 files changed

+117
-169
lines changed

.github/workflows/python-testing.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/shell-check.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/shell-testing.yml renamed to .github/workflows/testing.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
name: Shell Testing
22

33
on:
4-
push:
5-
branches: [ master ]
6-
paths:
7-
- 'src/**.sh'
8-
- 'tests/*.bats'
9-
- '.github/workflows/shell-testing.yml'
104
pull_request:
115
branches: [ master ]
126
paths:
13-
- 'src/**.sh'
14-
- 'tests/*.bats'
15-
- '.github/workflows/shell-testing.yml'
16-
workflow_run:
17-
workflows:
18-
- 'Shellcheck'
19-
types:
20-
- completed
7+
- '**.sh'
8+
- '**.bats'
9+
- '.github/workflows/testing.yml'
2110

2211
env:
2312
HOMEBREW_NO_AUTO_UPDATE: 1
2413

2514
jobs:
15+
checkout-code:
16+
steps:
17+
- uses: pre-commit/action@v3.0.0
18+
- uses: pre-commit-ci/lite-action@v1.0.1
19+
if: always()
2620
unit:
21+
needs: [checkout-code]
2722
runs-on: ${{ matrix.os }}
2823
strategy:
2924
fail-fast: false

.gitmodules

Lines changed: 0 additions & 9 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ ci:
22
skip: [poetry-lock]
33

44
repos:
5+
- repo: https://github.com/koalaman/shellcheck-precommit
6+
rev: v0.9.0
7+
hooks:
8+
- id: shellcheck
9+
files: '\.(bats|sh)$'
510

6-
- repo: https://github.com/python-poetry/poetry
7-
rev: '1.7.0'
11+
- repo: https://github.com/iamthefij/docker-pre-commit
12+
rev: v3.0.1
813
hooks:
9-
- id: poetry-check
10-
files: '^pyproject\.toml$'
11-
- id: poetry-lock
12-
files: '^pyproject\.toml$'
13-
args: [ '--no-update' ]
14+
- id: docker-compose-check
1415

1516
- repo: https://github.com/pre-commit/pre-commit-hooks
1617
rev: v4.5.0
@@ -25,13 +26,3 @@ repos:
2526
args: [ --unsafe ]
2627
- id: detect-private-key
2728
- id: trailing-whitespace
28-
29-
- repo: https://github.com/psf/black
30-
rev: 23.11.0
31-
hooks:
32-
- id: black
33-
34-
- repo: https://github.com/pre-commit/mirrors-mypy
35-
rev: 'v1.7.0'
36-
hooks:
37-
- id: mypy

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM alpine:3.17
2+
3+
ENV BATS_SUPPORT_VERSION='0.3.0'
4+
ENV BATS_ASSERT_VERSION='2.1.0'
5+
ENV BATS_FILE_VERSION='0.4.0'
6+
7+
RUN apk add --no-cache \
8+
attr \
9+
bats \
10+
coreutils \
11+
diffutils \
12+
grep \
13+
make
14+
15+
16+
WORKDIR /opt
17+
18+
RUN wget -q "https://github.com/bats-core/bats-support/archive/refs/tags/v${BATS_SUPPORT_VERSION}.zip" -O support.zip && \
19+
unzip -q support.zip && \
20+
mv bats-support-${BATS_SUPPORT_VERSION} bats-support && \
21+
rm support.zip && \
22+
wget -q "https://github.com/bats-core/bats-assert/archive/refs/tags/v${BATS_ASSERT_VERSION}.zip" -O assert.zip && \
23+
unzip -q assert.zip && \
24+
mv bats-assert-${BATS_ASSERT_VERSION} bats-assert && \
25+
rm assert.zip && \
26+
wget -q "https://github.com/bats-core/bats-file/archive/refs/tags/v${BATS_FILE_VERSION}.zip" -O file.zip && \
27+
unzip -q file.zip && \
28+
mv bats-file-${BATS_FILE_VERSION} bats-file && \
29+
rm file.zip
30+
31+
CMD bash -c 'bats tests'

Makefile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ DESTLIBDIR=/usr/local/lib/dropboxignore
44

55
# run shell tests
66
# bats should be in PATH
7-
shell-tests :
8-
git submodule update --init
9-
bats tests
107

11-
# run python tests
12-
python-tests :
13-
poetry run pytest --cov=src tests/
14-
15-
test : shell-tests python-tests
8+
test :
9+
docker-compose run dropboxignore-tests
1610

1711
# install dropboxignore
1812
install :

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<a href='https://dropboxignore.simakis.me/en/latest/?utm=gh'>
88
<img src='https://github.com/sp1thas/dropboxignore/actions/workflows/docs-deployment.yml/badge.svg' alt='Documentation Status' />
99
</a>
10-
<a href='https://results.pre-commit.ci/latest/github/sp1thas/dropboxignore/master'>
11-
<img src='https://results.pre-commit.ci/badge/github/sp1thas/dropboxignore/master.svg' alt='pre-commit.ci status' />
12-
</a>
1310
<a href="https://codecov.io/gh/sp1thas/dropboxignore">
1411
<img src="https://codecov.io/gh/sp1thas/dropboxignore/branch/master/graph/badge.svg?token=LBVA80F2DV"/>
1512
</a>

docker-compose.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
3+
services:
4+
dropboxignore-tests:
5+
build:
6+
context: "."
7+
dockerfile: "Dockerfile"
8+
image: "alpine-dropboxignore:latest"
9+
volumes:
10+
- './src:/opt/src'
11+
- './tests:/opt/tests'

docs/contributing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ For something that is bigger than a one or two line fix:
1414
* Be sure you have followed the code style for the project.
1515
* Update documentation accordingly
1616
* Add test cases if is applicable.
17+
* follow ![development](development.md) guidelines
1718

1819
## How to report a bug
1920

docs/development.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Developemt Guidelines
2+
3+
Here you will find details on how to set up a dev environment in order to develop a new feature or fix a bug.
4+
5+
## Dev environment
6+
7+
8+
### Re-requisites
9+
10+
- Docker
11+
- pre-commit
12+
13+
## Setup
14+
15+
After forking the repo, navigate in the project and:
16+
17+
```shell
18+
pre-commit install
19+
```

docs/testing.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# Testing
22

3-
Tests of dropboxignore are written using [bats](https://github.com/bats-core/bats-core) and they live inside the
4-
`tests` folder. You can run them using the `Makefile`:
3+
Tests of dropboxignore are written using [bats,](https://github.com/bats-core/bats-core) and they live inside the
4+
`tests` folder. You can run them using the `Makefile` (docker and docker-compose should be installed):
55

66
!!! info
7-
Make sure that bats is installed in your system and also in you `PATH` (use your package manager
8-
[[1](https://formulae.brew.sh/formula/bats-core), [2](https://packages.debian.org/buster/bats),
9-
[3](https://archlinux.org/packages/community/any/bash-bats/) ] or install it from
10-
[source](https://github.com/bats-core/bats-core)).
7+
Make sure that Docker and docker-compose are installed.
118

129
```shell
13-
$ make shell-tests
10+
$ make test
1411
```
1512

1613
If you are planning to implement a new feature, make sure that the necessary test cases have been added.

libs/bats-assert

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/bats-file

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/bats-support

Lines changed: 0 additions & 1 deletion
This file was deleted.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ nav:
3333
- 'Get started': 'getting-started.md'
3434
- 'CLI': 'cli.md'
3535
- 'Development':
36+
- Development: 'development.md'
3637
- Contributing: 'contributing.md'
3738
- Testing: 'testing.md'
3839

src/bin/cli.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 && pwd -P )"
77

88
if [ "$SCRIPT_PATH" == "/usr/local/bin" ]; then
99
LIB_PATH="/usr/local/lib/dropboxignore"
10+
elif [ "$SCRIPT_PATH" == "/code" ]; then
11+
LIB_PATH="/code/src/lib"
1012
else
1113
LIB_PATH="$SCRIPT_PATH/../lib"
1214
fi

tests/test_delete.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ setup() {
88
@test "Test delete command" {
99
mkdir "$BATS_TEST_TMPDIR/other"
1010
touch "$BATS_TEST_TMPDIR/other/$DROPBOXIGNORE_NAME"
11-
run $dropboxignore delete "$BATS_TEST_TMPDIR"
11+
run ${dropboxignore:?} delete "$BATS_TEST_TMPDIR"
1212
assert_success
1313
assert_file_not_exist "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
1414
assert_file_not_exist "$BATS_TEST_TMPDIR/other/$DROPBOXIGNORE_NAME"

tests/test_generate.bats

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
#!/usr/bin/env bash
22
# shellcheck shell=bash
3+
# shellcheck disable=SC2034
34
setup() {
45
load 'test_helper/common-setup'
56
_common_setup
67
}
78

89
@test "Test generate command when .dropboxignore file not exists" {
9-
rm -rf "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
10-
run $dropboxignore generate "$BATS_TEST_TMPDIR"
10+
rm -rf "${BATS_TEST_TMPDIR:?}/$DROPBOXIGNORE_NAME"
11+
run ${dropboxignore:?} generate "$BATS_TEST_TMPDIR"
1112
assert_success
1213
assert_file_exist "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
1314
assert_output --partial "Created file: .dropboxignore"
1415
assert_output --partial "Total number of generated files: 1"
1516
}
1617

1718
@test "Test generate command when .dropboxignore file exists" {
18-
run $dropboxignore generate "$BATS_TEST_TMPDIR"
19+
run ${dropboxignore:?} generate "$BATS_TEST_TMPDIR"
1920
assert_success
2021
assert_file_exist "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
2122
assert_output --partial "Total number of generated files: 0"
2223
}
2324

2425
@test "Test generate command when .gitignore file not exists" {
2526
rm "$BATS_TEST_TMPDIR/$GITIGNORE_NAME" "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
26-
run $dropboxignore generate "$BATS_TEST_TMPDIR"
27+
run ${dropboxignore:?} generate "$BATS_TEST_TMPDIR"
2728
assert_success
2829
assert_file_not_exist "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
2930
assert_file_not_exist "$BATS_TEST_TMPDIR/$GITIGNORE_NAME"
@@ -34,7 +35,7 @@ setup() {
3435
rm "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
3536
echo "a
3637
!something" > "$BATS_TEST_TMPDIR/$GITIGNORE_NAME"
37-
run $dropboxignore generate "$BATS_TEST_TMPDIR"
38+
run ${dropboxignore:?} generate "$BATS_TEST_TMPDIR"
3839
assert_success
3940
assert_file_not_exist "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
4041
assert_output --partial ".gitignore contains exception patterns, will be ignored"

tests/test_genupi.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ setup() {
66
}
77

88
@test "Test genupi command" {
9-
rm -rf "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
10-
run $dropboxignore genupi "$BATS_TEST_TMPDIR"
9+
rm -rf "${BATS_TEST_TMPDIR:?}/$DROPBOXIGNORE_NAME"
10+
run ${dropboxignore:?} genupi "$BATS_TEST_TMPDIR"
1111
assert_success
1212
assert_file_exist "$BATS_TEST_TMPDIR/$DROPBOXIGNORE_NAME"
1313
assert_file_exist "$BATS_TEST_TMPDIR/$GITIGNORE_NAME"

0 commit comments

Comments
 (0)