Skip to content

Commit

Permalink
tests(cli): add initial CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Jul 27, 2023
1 parent d734514 commit 836846f
Show file tree
Hide file tree
Showing 6 changed files with 568 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
fail_ci_if_error: true
- name: Build
run: make build
- name: Test CLI
run: make test-cli
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ setup-kong-ee:
test-integration:
go test -v -tags=integration \
-race \
./tests/integration/...
./tests/integration/...

.PHONY: test-cli
test-cli: build
tests/cli/test.sh --suite "decK-cli test suite"
27 changes: 27 additions & 0 deletions tests/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# CLI tests

This suite of tests is not intended to do complex integration tests, but simple
unit-test like tests of the CLI flags. Testing allowed inputs, flag-combinations, etc.

## Running all tests
Using the `Makefile`;
```
make test-cli
```
or directly;
```
tests/cli/test.sh --suite "decK-cli test suite"
```

## Running a single file
```
tests/cli/mytestfile.test.sh
```
## Create a new test-file
To create a new testfile run:

```shell
tests/cli/test.sh --create tests/cli/mytestfile "decK-cli test suite"
```

instructions will be in the generated file.
41 changes: 41 additions & 0 deletions tests/cli/fixtures/mock-a-rena-oas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
openapi: 3.1.0

info:
description: Mock service for a popular song in the 90s
version: 0.0.1
title: Mock-a-rena
contact:
name: Los del Rio

servers:
- url: https://mockbin.org/requests
description: Mock-a-rena service

tags:
- name: mock
description: Hey.... mock-a-rena!
- name: a-rena
description: tag-arena

paths:
"/mock":
get:
summary: Mock, mock, mock, mock-a-rena
description: yeah yeah
operationId: mock
tags:
- mock
responses:
'200':
description: Success
"/a-rena":
get:
summary: hey hey
description: a-rena-description
operationId: a-rena
tags:
- marena
responses:
'200':
description: success
42 changes: 42 additions & 0 deletions tests/cli/mytestfile.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash


function run_test {
# the suite name below will only be used when running this file directly, when
# running through "test.sh" it must be provided using the "--suite" option.
tinitialize "decK-cli test suite" "${BASH_SOURCE[0]}"

tchapter "deck file openapi2kong"

ttest "accepts format 'json'"
./deck file openapi2kong --format json > /dev/null < tests/cli/fixtures/mock-a-rena-oas.yml
if [ $? -ne 0 ]; then
tfailure "--format=json was not accepted"
else
tsuccess
fi

ttest "accepts format 'yaml'"
./deck file openapi2kong --format yaml > /dev/null < tests/cli/fixtures/mock-a-rena-oas.yml
if [ $? -ne 0 ]; then
tfailure "--format=yaml was not accepted"
else
tsuccess
fi

ttest "--format has a default value"
./deck file openapi2kong > /dev/null < tests/cli/fixtures/mock-a-rena-oas.yml
if [ $? -ne 0 ]; then
tfailure "unspecified --format was not accepted"
else
tsuccess
fi

tfinish
}

# No need to modify anything below this comment

# shellcheck disable=SC1090 # do not follow source
[[ "$T_PROJECT_NAME" == "" ]] && set -e && if [[ -f "${1:-$(dirname "$(realpath "$0")")/test.sh}" ]]; then source "${1:-$(dirname "$(realpath "$0")")/test.sh}"; else source "${1:-$(dirname "$(realpath "$0")")/run.sh}"; fi && set +e
run_test
Loading

0 comments on commit 836846f

Please sign in to comment.