Testing localhost-only Loklak APIs

Loklak provides several APIs which are localhost-only! i.e. only localhost clients are granted access. For example:

This feature makes it difficult to integrate testing of such APIs with the main test-suite. Since we use Travis-CI for online testing, we would have to create an extra connection setup for online testing and offline (localhost) testing.

So in this dilemma, I had to come up with an approach which would allow the test-suite to recognise Travis-CI and take necessary actions to handle such conditions. After some reading, I came across PHP’s getenv() function which provides information of current environment variables.

So, in order to write tests for localhost-only APIs, I used getenv() as a check to differentiate between Travis and local tests.


Using this approach, tests for Settings and Accounts API were added. Code samples shown below!


This approach improves the tested code-coverage and integrates all unit tests into one file!

Testing localhost-only Loklak APIs