kapua
kapua copied to clipboard
REST API Framework, Runner and First Tests
This PR introduces framework for REST API testing. The PR consists of three parts:
- Adding Newman runner for running tests in CI (GHA and Travis - this tool is available in GitHub Marketplace)
- Enhancing docker-deploy.sh script
- Adding JSON file with Rest Api tests
The idea is this: We will write tests in Postman, as this is much faster that adding tests via Rest Assured or something else (it is also a much better collaboration tool than any others, so we can divide testing team into smaller fragments and also check the progress of others, etc.). After we add some tests, we will export this to a file "KapuaApiTestingPostman_collection.json", which is located in rest-api/test/ folder.
The tests will be run after every push and PR (I added a test-restApi stage into GHA yml file), but they can also be run locally:
- If you don't have Newman on you machine yet, install it with
npm install -g newman
- In terminal go to rest-api/test folder
- Run command
newman run KapuaApiTestingPostman_collection.json
Output should be something like this:
Although Travis is becoming obsolete I have upgraded Travis.yml file, so the rest-api tests will be run also there. There are just a couple of tests added in the JSON file, becasue rest-api tests tend to get very long (a lot of lines) and I wanted to avoid CQ.
Related Issue This PR is not related to any specific issue, but is rather a initial commit, which sets up the framework for rest api testing.
Screenshots /
Any side note on the changes made I have added a "smart" timeout to the docker-deploy.sh script because there were some trobules wtih running Rest API tests. The problem is, that once you run this script, docker containers get status "Running" although they are not properly started just yet - they need a minute or so to properly start. Without this addition, the Rest API tests will start as soon the docker-deploy.sh scripts completes and the tests will fail, because API container is not deployed. Therefore this timeout checks API container log for a certain string every 5 seconds (when this string appears the container is up and running), to see if the container is properly running or not. I have tested this and it works fine.
Because I had problems with PR #3231 (commits with wrong email), I have closed that one and opened new one, as I was unable to verify myself with old (unexisting and disabled) email.
Signed-off-by: Leonardo Gaube [email protected]
Codecov Report
Merging #3235 (87c72c3) into develop (99dde48) will decrease coverage by
3.06%
. The diff coverage isn/a
.
:exclamation: Current head 87c72c3 differs from pull request most recent head 19c072d. Consider uploading reports for the commit 19c072d to get more accurate results
@@ Coverage Diff @@
## develop #3235 +/- ##
=============================================
- Coverage 55.01% 51.95% -3.07%
+ Complexity 786 594 -192
=============================================
Files 1478 1478
Lines 30235 30235
Branches 2523 2523
=============================================
- Hits 16635 15708 -927
- Misses 12686 13665 +979
+ Partials 914 862 -52
This PR is currently failing because of issue #3262. After that is fixed, I will rebase and push.
Hey @Coduz, I have changed this PR so when this is merged, we will haev two gitHub actions - one is for "regular" build with Unit and Integration tests and other one with "-Pdocker" build with rest tests.
Because I had some problems with caching the docker images, I put everything in one stage (build + tests) - I hope this is OK.
Both flows have successfully passed, so this can be merged (I didn't research what happened with codeCov, but I can do it, if necessary).