Skip to content

Commit

Permalink
adding BATS core and supporting libraries
Browse files Browse the repository at this point in the history
removing dependency for user to have to install BATS
  • Loading branch information
coreydaley committed Oct 8, 2021
1 parent 8d6dba5 commit bd63cf1
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "test/e2e/bats/core"]
path = test/e2e/bats/core
url = https://github.com/bats-core/bats-core
[submodule "test/e2e/bats/support"]
path = test/e2e/bats/support
url = https://github.com/bats-core/bats-support
[submodule "test/e2e/bats/assert"]
path = test/e2e/bats/assert
url = https://github.com/bats-core/bats-assert
[submodule "test/e2e/bats/file"]
path = test/e2e/bats/file
url = https://github.com/bats-core/bats-file
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ test: test-unit test-e2e
test-unit:
go test $(GO_FLAGS) $(GO_TEST_FLAGS) $(CMD) $(PKG) $(ARGS)

# runs all end-to-end tests using bats, it assumes bats is installed
# looks for *.bats files in the test/e2e directory and runs them
test-e2e:
./test/e2e/e2e.bats
./hack/run-e2e.sh

# wait for KinD cluster to be on ready state, so tests can be performed
verify-kind:
Expand Down
16 changes: 15 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,22 @@ The install script waits for the Controller instance to be running.
[BATS][batsCore] is a testing framework for Bash. It's structured as a regular script with enhanced
syntax to define test cases, collect results, and more.

To run BATS based tests, make sure you have `bats` installed, and then execute:
The BATS core tool and it's supporting libraries are linked in this project as `git submodules`,
alleviating the need to install BATS yourself.

To run BATS based tests, make sure that you have cloned the project (including all submodules):

```sh
Option 1.)
$ git clone --recurse-submodules --depth 1 https://github.com/shipwright-io/cli.git

Option 2.) (if you did not clone using the above command)
$ cd /your/project/directory/cli
$ git submodule init
$ git submodule update
```

then run:
```sh
make test-e2e
```
Expand Down
5 changes: 5 additions & 0 deletions hack/run-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

for i in test/e2e/*.bats; do
./test/e2e/bats/core/bin/bats ${i}
done
1 change: 1 addition & 0 deletions test/e2e/bats/assert
Submodule assert added at 672ad1
1 change: 1 addition & 0 deletions test/e2e/bats/core
Submodule core added at 90a051
1 change: 1 addition & 0 deletions test/e2e/bats/file
Submodule file added at 17fa55
1 change: 1 addition & 0 deletions test/e2e/bats/support
Submodule support added at d140a6
Empty file modified test/e2e/e2e.bats
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion test/e2e/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function shp () {
${BIN} ${*}
}

# generate a random string of no more than 16 characters
function random_name () {
LC_ALL=C tr -dc a-z </dev/urandom | head -c64
LC_ALL=C tr -dc a-z </dev/urandom | head -c16
}

0 comments on commit bd63cf1

Please sign in to comment.