Skip to content

Commit

Permalink
test: add bashunit (#64)
Browse files Browse the repository at this point in the history
* chore: add bashunit to the repo

* chore: created folder for test and check that bashunit works

* chore: snapshot for test_should_ignore_files_with_glob

* chore: add pipeline

* chore: snapshot update

* git ignore bashunit, rather install it as vendor

* chore: code style

* chore: fix installed bashunit version

---------

Co-authored-by: Chemaclass <[email protected]>
Co-authored-by: katarn <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2023
1 parent d269449 commit 54c3c1d
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEFAULT_PATH=tests
13 changes: 13 additions & 0 deletions .github/CONTRIBUTIONS.md
Original file line number Diff line number Diff line change
@@ -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
```
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/

lib/bashunit
4 changes: 4 additions & 0 deletions install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

## bashunit
curl -s https://bashunit.typeddevs.com/install.sh | bash -s -- lib 0.10.0
74 changes: 74 additions & 0 deletions tests/fixtures/test_should_ignore_files_with_regex_response
Original file line number Diff line number Diff line change
@@ -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
}
]
14 changes: 14 additions & 0 deletions tests/github_test.sh
Original file line number Diff line number Diff line change
@@ -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[*]}")"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
394

0 comments on commit 54c3c1d

Please sign in to comment.