Skip to content

Commit a11cacf

Browse files
author
Sebastiaan Verbeek
authored
feat: add bats documentation (#236)
1 parent 4683d58 commit a11cacf

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed

bin/tests/bootstrap-integration.bats

-36
This file was deleted.

bin/tests/bootstrap-unit.bats renamed to bin/tests/bootstrap.bats

+19
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,23 @@ teardown () {
3636
assert_file_exist "$env_path/charts"
3737
assert_file_exist "$env_path/clouds"
3838
assert_file_exist "$env_path/teams"
39+
}
40+
41+
@test "executing bootstrap.sh should pass with new ENV_DIR (otomi-values) folder" {
42+
git init "$ENV_DIR"
43+
run bin/bootstrap.sh
44+
assert_success
45+
}
46+
47+
@test "executing bootstrap.sh should fail without new ENV_DIR (otomi-values) folder" {
48+
unset ENV_DIR
49+
run bin/bootstrap.sh
50+
assert_failure
51+
}
52+
53+
@test "executing bootstrap.sh multiple times should pass with new ENV_DIR (otomi-values)" {
54+
git init "$test_temp_dir"
55+
bin/bootstrap.sh
56+
run bin/bootstrap.sh
57+
assert_success
3958
}

docs/BATS.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# BATS testing framework
2+
3+
This document is relevant starting from [v0.11.52](https://github.com/redkubes/otomi-core/releases/tag/v0.11.52).
4+
5+
## Where can I find BATS?
6+
7+
The otomi/tools:1.4.10 includes the [bats framework](https://github.com/bats-core/bats-core), including libraries [bats-assert](https://github.com/ztombol/bats-assert), [bats-file](https://github.com/ztombol/bats-support) and [bats-support](https://github.com/ztombol/bats-support). These links include relevant documentation, such as syntax, which won't be discussed on this page.
8+
9+
Example of calling the binary:
10+
11+
`docker run --rm otomi/tools:1.4.10 bats bin/tests`
12+
13+
This example assumes tests exist in the container directory `otomi-core/bin/tests`. You can call bats with a directory as parameter and it will execute any `*.bats` file.
14+
15+
## How should I add tests?
16+
17+
Test files should have the .bats extension, otherwise they will not be executed.
18+
19+
## How should I name the test files?
20+
21+
Usually you will name the test file after the shell file holding the code you are testing, but with the `.bats` extension.
22+
23+
Example with a bootstrap.sh file:
24+
25+
`bootstrap.bats`
26+
27+
## How do I use the BATS libraries?
28+
29+
The tests will run in the otomi-core container, which has bats libs in `/usr/local/lib/bats-*`. The following snippet will include them in a test file:
30+
31+
```
32+
lib_dir="/usr/local/lib"
33+
34+
load "$lib_dir/bats-support/load.bash"
35+
load "$lib_dir/bats-assert/load.bash"
36+
load "$lib_dir/bats-file/load.bash"
37+
```

docs/CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Please make sure to add all the artifacts from the Definition of Done, which inc
2121
1. Spec validation of values happens automatically in the values repo by using `otomi commit`
2222
2. Linting of k8s output (manifests) that are generated from the `.demo/env/*` input happens in the build pipelines.
2323
It tests k8s output from the stack for correct CRs based on their CRDs and OPA rules defined.
24-
Therefor it is very important to always add test data that generates all of your templates (to keep up coverage).
24+
Therefore it is very important to always add test data that generates all of your templates (to keep up coverage).
25+
3. Scripting is done in `bash`, and these shell scripts are available in `bin/*`. We use the `bats` testing framework as explained in [documentation about bats](./BATS.md).
2526

2627
### 2. End-to-end tests
2728

0 commit comments

Comments
 (0)