test: enable travis-ci with bats (#108)

- add .travis.yml.
- move bats fixtures to .bats extension, since it allows detection of test
files automatically by file extension.
- use BATS_TEST_DIRNAME variable to compute location of COMMAND.
- IMPORTANT: use `echo "$output">&2` before final check so that we can debug
  the test cases by their output

Ref #2.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-12-22 13:22:08 -08:00 committed by GitHub
parent 2b5bf4e429
commit 845f3b690b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

8
.travis.yml Normal file
View File

@ -0,0 +1,8 @@
before_install:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
- sudo curl -fsSL -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.1/bin/linux/amd64/kubectl
- sudo chmod +x /usr/bin/kubectl
script:
- bats test/

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bats
COMMAND=../kubectx
COMMAND="$BATS_TEST_DIRNAME/../kubectx"
@test "--help should not fail" {
run ${COMMAND} --help

View File

@ -1,13 +1,15 @@
#!/usr/bin/env bats
COMMAND=../kubens
COMMAND="${BATS_TEST_DIRNAME}/../kubens"
@test "--help should not fail" {
run ${COMMAND} --help
echo "$output">&2
[ "$status" -eq 0 ]
}
@test "-h should not fail" {
run ${COMMAND} -h
echo "$output">&2
[ "$status" -eq 0 ]
}