zerocode icon indicating copy to clipboard operation
zerocode copied to clipboard

Use environnent var to override properties files

Open deblockt opened this issue 5 years ago • 8 comments

We want to run our acceptance tests on our ci. On the ci to avoid issue between multiple builds we use random port. Using fixed properties we can not connect acceptance tests with our application (because of port configuration).

It can be fine to be able to override properties by environements var. Using env var we can allow dynamic port.

AC1: As an automation-engineer or developer I want to start my automated tests in a CI environment. So I use the docker-composer to start the development environment with kafka and API on random ports to avoid conflicts with multiple parallel build And I want to configure the zerocode acceptance test with the docker's random ports to link my acceptance tests with the development environment.

deblockt avatar Jan 15 '20 17:01 deblockt

@deblockt , Just going through the PR. I have some questions.

  1. Are these random ports going to be deterministic? It's random, but deterministic before the run.
  2. How are they set during runtime?

e.g.

key.to.override=1234

Assuming the port is 1234 above, it becomes a fixed port?

We already have a feature to support ENV vars, can't that be useful? Can you have a look at https://github.com/authorjapps/zerocode/issues/282 @santhoshTpixler , can you have a look at the issue and the PR please?

Is it possible for you to add slightly more details to the issues description? I have left some TODO placeholders for you to fill it easily 👍

authorjapps avatar Jan 18 '20 08:01 authorjapps

@deblockt Already we have support for accessing environment variables from the JSON files. But in your case, you might want to change the port in the host.properties before you run the tests to access the application.

You can append the new property with the port and start the test to properly access the application running on the random port.

Eg: If your application is running on $PORT, then

echo "restful.application.endpoint.port=$PORT" >> host.properties

santhoshTpixler avatar Jan 23 '20 12:01 santhoshTpixler

@authorjapps I have fill the TODO. Ports are random and generated by docker. there are set during the environment start.

@santhoshTpixler yes we can override the host.properties file using command line, but it's not a simple way to work. Using environment var or JVM properties is a common way to define connection information between two systems.

deblockt avatar Jan 26 '20 15:01 deblockt

@deblockt , Just trying to figure out, Who(how) sets the properties into System properties or Env variables? Meaning - how the ports are populated into the Env variables?

authorjapps avatar Mar 04 '20 15:03 authorjapps

It's a script runned by the ci. the script do :

  • start docker-compose on random port
  • get port chossen by docker-composer
  • set the jvm args or env var to be able to run tests
  • run tests

deblockt avatar Mar 04 '20 16:03 deblockt

ok. Then assuming random_port is one of the system property which holds the random port, Can't you access the following way... (already supported)?

      {
         "name": "verify_person", 
         "url": "${web.application.endpoint.host}:${SYSTEM.PROPERTY:random_port}/api/v1/persons/303022",
         "operation": "GET",
         "request": {
         },
         "assertions": {
            "status": 200,
            "body": {
               "id": "303022"
            }
         }
      }

Note::: This ${web.application.endpoint.host} is just for example, but can be any key from the target config.

or

${SYSTEM.ENV:random_port} <--- For accessing env variable values

authorjapps avatar Mar 04 '20 17:03 authorjapps

Yes I can do that for API endpoint, but it's not easy to read... JSON test are already very hard to read. And are there a solution for kafka connection?

deblockt avatar Mar 06 '20 17:03 deblockt

@deblockt , I pinged you on the Slack couple of time... No response :-(

It looks like you are lookin for some other solution.

It's not clear from your PR what problem you are trying to solve(not matching the issue description)...

I have added some comments to your PR.

Can you address that?

Are you lookin for ${random_port} instead of ${SYSTEM.PROPERTY:random_port} as a short/quick DSL?


And are there a solution for kafka connection?

Ans: This is unclear. How it is different from other hosts/ports? any examples?

authorjapps avatar Mar 07 '20 10:03 authorjapps