kapua icon indicating copy to clipboard operation
kapua copied to clipboard

REST API Framework, Runner and First Tests

Open LeoNerdoG opened this issue 4 years ago • 3 comments

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:

  1. If you don't have Newman on you machine yet, install it with npm install -g newman
  2. In terminal go to rest-api/test folder
  3. Run command newman run KapuaApiTestingPostman_collection.json

Output should be something like this: Screenshot 2021-02-12 at 13 59 13

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]

LeoNerdoG avatar Feb 11 '21 13:02 LeoNerdoG

Codecov Report

Merging #3235 (87c72c3) into develop (99dde48) will decrease coverage by 3.06%. The diff coverage is n/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 Impacted file tree graph

@@              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     
Impacted Files Coverage Δ Complexity Δ
...engine/jbatch/driver/JbatchJobRunningStatuses.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-3.00%)
...ne/queue/jbatch/QueuedJobExecutionCreatorImpl.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-9.00%)
...ssage/kura/app/notification/KuraNotifyMessage.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-1.00%)
...ment/exception/DeviceManagementSendErrorCodes.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...t/exception/DeviceManagementTimeoutErrorCodes.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...nternal/JobDeviceManagementOperationQueryImpl.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-1.00%)
...ernal/JobDeviceManagementOperationCreatorImpl.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-5.00%)
...al/JobDeviceManagementOperationListResultImpl.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (-1.00%)
...rnal/ManagementOperationNotificationQueryImpl.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...al/ManagementOperationNotificationCreatorImpl.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
... and 83 more

codecov[bot] avatar Feb 11 '21 13:02 codecov[bot]

This PR is currently failing because of issue #3262. After that is fixed, I will rebase and push.

LeoNerdoG avatar Feb 26 '21 08:02 LeoNerdoG

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).

LeoNerdoG avatar Mar 02 '21 12:03 LeoNerdoG