diff --git a/.env b/.env new file mode 100644 index 0000000..d3c66d6 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DEFAULT_PATH=tests \ No newline at end of file diff --git a/.github/CONTRIBUTIONS.md b/.github/CONTRIBUTIONS.md new file mode 100644 index 0000000..306974f --- /dev/null +++ b/.github/CONTRIBUTIONS.md @@ -0,0 +1,13 @@ +# Testing + +Tests written in [bashunit](https://bashunit.typeddevs.com/). + +Install vendor dependencies: +```bash +./install-dependencies.sh +``` + +Run all tests: +```bash +./lib/bashunit tests +``` diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a24380b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +on: + pull_request: + push: + branches: + - main + +name: Tests +jobs: + tests: + name: "Run tests" + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + + - name: "Install dependencies" + run: ./install-dependencies.sh + + - name: "Tests" + run: ./lib/bashunit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5c1afb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ + +lib/bashunit diff --git a/install-dependencies.sh b/install-dependencies.sh new file mode 100755 index 0000000..b8d466d --- /dev/null +++ b/install-dependencies.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +## bashunit +curl -s https://bashunit.typeddevs.com/install.sh | bash -s -- lib 0.10.0 diff --git a/tests/fixtures/test_should_ignore_files_with_regex_response b/tests/fixtures/test_should_ignore_files_with_regex_response new file mode 100644 index 0000000..b6af2cd --- /dev/null +++ b/tests/fixtures/test_should_ignore_files_with_regex_response @@ -0,0 +1,74 @@ +[ + { + "filename": ".editorconfig", + "additions": 9, + "deletions": 0, + "changes": 9 + }, + { + "filename": ".github/workflows/ci.yml", + "additions": 17, + "deletions": 0, + "changes": 17 + }, + { + "filename": "asdasdasd.lock", + "additions": 1188, + "deletions": 0, + "changes": 1188 + }, + { + "filename": "entrypoint.sh", + "additions": 4, + "deletions": 4, + "changes": 8 + }, + { + "filename": "src/ensure.sh", + "additions": 4, + "deletions": 4, + "changes": 8 + }, + { + "filename": "src/github.sh", + "additions": 89, + "deletions": 76, + "changes": 165 + }, + { + "filename": "src/github_actions.sh", + "additions": 1, + "deletions": 1, + "changes": 2 + }, + { + "filename": "src/inner.lock", + "additions": 1188, + "deletions": 0, + "changes": 1188 + }, + { + "filename": "src/labeler.sh", + "additions": 48, + "deletions": 48, + "changes": 96 + }, + { + "filename": "src/log.sh", + "additions": 17, + "deletions": 0, + "changes": 17 + }, + { + "filename": "src/main.sh", + "additions": 34, + "deletions": 23, + "changes": 57 + }, + { + "filename": "src/misc.sh", + "additions": 10, + "deletions": 14, + "changes": 24 + } +] \ No newline at end of file diff --git a/tests/github_test.sh b/tests/github_test.sh new file mode 100644 index 0000000..408b11b --- /dev/null +++ b/tests/github_test.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +function set_up() { + source ./src/misc.sh + source ./src/github.sh +} + +function test_should_ignore_files_with_glob() { + local -r pr_number=123 + local -r files_to_ignore=("*.lock" ".editorconfig") + mock curl cat ./tests/fixtures/test_should_ignore_files_with_regex_response + + assert_match_snapshot "$(github::calculate_total_modifications "$pr_number" "${files_to_ignore[*]}")" +} diff --git a/tests/snapshots/github_test_sh.test_should_ignore_files_with_glob.snapshot b/tests/snapshots/github_test_sh.test_should_ignore_files_with_glob.snapshot new file mode 100644 index 0000000..0ca45a0 --- /dev/null +++ b/tests/snapshots/github_test_sh.test_should_ignore_files_with_glob.snapshot @@ -0,0 +1 @@ +394