2019-07-12 15:47:55 +08:00
# Running Tests
2015-03-27 14:24:04 -07:00
2019-07-12 15:47:55 +08:00
Dokku has a full test suite to assist in quick iterating development. These tests include a linter using [shellcheck ](https://github.com/koalaman/shellcheck ), functional unit tests using the [Bats testing framework ](https://github.com/bats-core/bats-core ), and a deployment suite of example apps that use the most popular languages and frameworks.
2015-03-27 14:24:04 -07:00
2016-07-30 16:51:31 -04:00
We maintain the Dokku test harness within the `tests` directory:
2015-03-27 14:24:04 -07:00
2016-07-30 16:51:31 -04:00
- `tests/unit/*.bats` : Bats tests
- `tests/apps/` : Example applications that can be used for tests
## Continuous Integration
2022-12-29 00:29:49 -05:00
All pull requests have tests run against them on [GitHub Actions ](https://github.com/features/actions ), a continuous integration platform that provides Docker support for Ubuntu Focal 20.04.
2015-03-27 14:24:04 -07:00
2019-07-12 15:47:55 +08:00
If you wish to skip tests for a particular commit, e.g. documentation changes, you may add the `[ci skip]` designator to your commit message. Commits that _ should _ be tested but have the above designator will not be merged.
2016-07-30 16:51:31 -04:00
2022-12-29 00:29:49 -05:00
While we do provide official packages for a variety of platforms, as our test suite currently runs on Ubuntu Focal 20.04, we only provide official installation support for that platform and the latest LTS release of Ubuntu (currently 20.04).
2016-07-30 16:51:31 -04:00
## Local Test Execution
2015-03-27 14:24:04 -07:00
2022-10-12 22:08:50 -04:00
### Vagrant VM
2019-07-12 15:47:55 +08:00
- Setup Dokku in a [Vagrant VM ](/docs/getting-started/install/vagrant.md ).
2016-07-30 16:51:31 -04:00
- Run the following to setup tests and execute them:
2015-03-27 14:24:04 -07:00
```shell
2016-07-04 20:22:57 -04:00
vagrant ssh
sudo su -
cd ~/dokku
make ci-dependencies setup-deploy-tests
2015-03-27 14:24:04 -07:00
```
2019-07-12 15:47:55 +08:00
After making changes to your local Dokku clone, don't forget to update the Vagrant Dokku install.
```shell
# update vagrant dokku install from local git clone
make copyfiles
# build a specific plugin
make go-build-plugin copyplugin PLUGIN_NAME=apps
```
2022-10-12 22:41:47 -04:00
### VSCode Dev Container
- Open Dokku in a VSCode DevContainer
- Run the following in the VSCode terminal to setup tests and execute them:
```shell
make ci-dependencies setup-deploy-tests
```
After making changes to your local Dokku clone, don't forget to update the Vagrant Dokku install.
```shell
# update vagrant dokku install from local git clone
make copyfiles
# build a specific plugin
make go-build-plugin copyplugin PLUGIN_NAME=apps
```
2022-10-12 22:08:50 -04:00
### Executing tests
Execute the entire test suite (linter, bats tests, and app deployment tests):
```shell
make test
```
Run the linter
```shell
make lint
```
Execute all bats tests
```shell
make unit-tests
```
Execute all app deployment tests
```shell
make deploy-tests
```
#### Executing App Tests
You may run a specific app deployment tests with a target similar to:
2016-07-30 16:51:31 -04:00
```shell
make deploy-test-nodejs-express
```
2016-09-03 04:39:12 -04:00
For a full list of test make targets check out `tests.mk` in the root of the Dokku repository.
2018-12-29 08:01:14 -05:00
2022-10-12 22:08:50 -04:00
#### Executing a single test suite
2018-12-29 08:01:14 -05:00
When working on a particular plugin, it may be useful to run _ only _ a particular test suite. This can be done by specifying the test suite path:
```shell
2022-10-12 22:08:50 -04:00
bats tests/unit/apps_1.bats
2018-12-29 08:01:14 -05:00
```
It is also possible to target multiple test suites at a time.
```shell
2022-10-12 22:08:50 -04:00
bats tests/unit/apps_1.bats tests/unit/certs.bats
2018-12-29 08:01:14 -05:00
```
2022-10-12 22:08:50 -04:00
#### Executing a single test
2018-12-29 08:01:14 -05:00
2019-07-12 15:47:55 +08:00
In order to increase testing velocity, a wrapper script around Bats is available that can be used to run a single test case within a suite.
2018-12-29 08:01:14 -05:00
2020-12-11 11:45:15 -05:00
Tests within a suite may be listed by specifying the suite as a parameter to `bats` .
2018-12-29 08:01:14 -05:00
```shell
2022-10-12 22:08:50 -04:00
bats tests/unit/apps_1.bats
2018-12-29 08:01:14 -05:00
```
2020-12-11 11:45:15 -05:00
A single test can be specified via the `--filter` argument. The tests are selected via regex match, and all matches are executed.
2018-12-29 08:01:14 -05:00
```shell
2022-10-12 22:08:50 -04:00
bats --filter list tests/unit/apps_1.bats
2018-12-29 08:01:14 -05:00
```