Skip to content

Commit

Permalink
fix: move the CTS around to prepare for multi-languages support (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Jan 14, 2022
1 parent 413f6f8 commit 88f1c09
Show file tree
Hide file tree
Showing 119 changed files with 1,010 additions and 890 deletions.
25 changes: 18 additions & 7 deletions doc/CTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@ It is automaticaly generated for all languages, from a JSON entry point.
## How to run it

```bash
yarn cts:generate
yarn cts:test
yarn docker cts:generate
yarn docker cts:test
```

If you only want to generate the tests for a set of languages, you can run:
If you only want to generate the tests for a language, you can run:

```bash
yarn cts:generate "javascript ruby"
yarn docker cts:generate javascript
```

Or for a specific client:

```bash
yarn docker cts:generate all search
```

Or a specific language and client:

```bash
yarn docker cts:generate javascript search
```

## How to add test

The test generation script requires a JSON file name from the `operationId` (e.g. `search.json`), located in the `CTS/<client>/` folder (e.g. `CTS/search/`).
The test generation script requires a JSON file name from the `operationId` (e.g. `search.json`), located in the `CTS/<client>/requests/` folder (e.g. `CTS/search/requests/`).

```json
[
Expand All @@ -45,8 +57,7 @@ And that's it! If the name of the file matches a real `operationId` in the spec,

## How to add a new language

- Add the language in the array `languages` in `tests/generateCTS.ts`.
- Create a template in `test/CTS/templates/<your language>.mustache` that parse a array of test into your test framework of choice
- Create a template in `test/CTS/templates/<your language>/requests.mustache` that parses an array of tests into the test framework of choice

When writing your template, here is a list of variables accessible from `mustache`:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"build:specs": "./scripts/builds/specs.sh ${0:-all} ${1:-yaml}",
"build": "yarn build:specs && yarn build:clients",
"clean": "rm -rf **/dist **/build **/node_modules",
"cts:generate": "yarn workspace tests start",
"cts:test": "yarn workspace tests test",
"cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh yarn workspace tests generate ${0:-all} ${1:-all} && yarn workspace tests lint:fix",
"cts:test": "./scripts/multiplexer.sh ./scripts/runCTS.sh ${0:-javascript} all",
"docker:build": "./scripts/docker/build.sh",
"docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation",
"docker:mount": "./scripts/docker/mount.sh",
Expand Down
16 changes: 13 additions & 3 deletions scripts/multiplexer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
# Move to the root (easier to locate other scripts)
cd ${DIR}/..

CMD=$1
LANGUAGE=$2
CLIENT=$3
CMD=${@:1:$#-2} # all arguments but the last 2
LANGUAGE=${@: -2:1} # before last argument
CLIENT=${@: -1} # last argument

if [[ $CMD == "./scripts/playground.sh" ]] && ([[ $LANGUAGE == "all" ]] || [[ $CLIENT == "all" ]]); then
echo "You cannot use 'all' when running the playground, please specify the language and client"

exit 1
fi

if [[ $CMD == "./scripts/runCTS.sh" ]]; then
if [[ $CLIENT == "all" ]]; then
CLIENT=search # dummy client to only run once
else
echo "You must use 'all' clients when testing the CTS, as they all run at the same time"

exit 1
fi
fi

LANGUAGES=()
CLIENTS=()

Expand Down
21 changes: 21 additions & 0 deletions scripts/runCTS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Break on non-zero code
set -e

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
# Move to the root (easier to locate other scripts)
cd ${DIR}/..

lang=$1

# Run the pre generation script if it exists.
run_cts() {
if [[ $lang == 'javascript' ]]; then
yarn workspace javascript-tests test
elif [[ $lang == 'java' ]]; then
mvn clean compile exec:java -f tests/output/java/pom.xml
fi
}

run_cts
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
276 changes: 0 additions & 276 deletions tests/generateCTS.ts

This file was deleted.

Empty file.
File renamed without changes.
Loading

0 comments on commit 88f1c09

Please sign in to comment.