Skip to content

Commit

Permalink
Docker usage focus on using bats isolated in other project
Browse files Browse the repository at this point in the history
Focus on how to use bats in another project.

Document how one loads libraries, solves bats-core#707.
  • Loading branch information
arve0 authored and martin-schulze-vireso committed Jul 24, 2023
1 parent a6eec43 commit 6451436
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions docs/source/docker-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@

- [Docker Usage Guide](#docker-usage-guide)
* [Basic Usage](#basic-usage)
* [Basic Usage for bats project](#basic-usage-for-bats-project)
* [Docker Gotchas](#docker-gotchas)
* [Extending from the base image](#extending-from-the-base-image)

## Basic Usage

For test suites that are intended to run in isolation from the bats project, you can mount the test directory and run the [official bats docker image](https://hub.docker.com/r/bats/bats):

```bash
$ docker run -it -v "$PWD:/code" bats/bats:latest /code/test
```

Docker image includes libaries like [bats-support](https://github.com/bats-core/bats-support) and [bats-assert](https://github.com/bats-core/bats-assert), which can be loaded in `setup` like this:

```bash
setup() {
bats_load_library bats-support
bats_load_library bats-assert
}
```

## Basic Usage for Bats Project

To build and run `bats`' own tests:
```bash
$ git clone https://github.com/bats-core/bats-core.git
Expand All @@ -29,12 +47,6 @@ $ docker run -it -v "$PWD:/opt/bats" bats/bats:latest /opt/bats/test
```
This runs the `test/` directory from the bats-core repository inside the bats Docker container.

For test suites that are intended to run in isolation from the project (i.e. the tests do not depend on project files outside of the test directory), you can mount the test directory by itself and execute the tests like so:

```bash
$ docker run -it -v "$PWD:/code" bats/bats:latest /code/test
```

## Docker Gotchas

Relying on functionality provided by your environment (ssh keys or agent, installed binaries, fixtures outside the mounted test directory) will fail when running inside Docker.
Expand Down

0 comments on commit 6451436

Please sign in to comment.