Execute a system command, bash script via REST API

vutil provides a REST API to execute commands on the test machine in which test application's data resides. Now with the help of this API, we can insert database dumps through commands and these commands can be invoked via REST APIs.

This API execute commands on machines on which this utility is installed.

API Endpoint:

The API format is 

POST {{vutilBaseURL}}/execute/command

Here {{vutilBaseURL}} is the base URL of the vutil server.

and this API accepts a single body parameter "command" and its value is the command which you want to execute on your system.

How to use this API

Assuming that vutil is running on port 4080 and vutil base URL is "http://localhost:4080"

Let us try to execute a simple command `echo hello` via this utility. Simply create a test case with URL "http://localhost:4080".

Your test case might look like:

and provide a request parameter "command" as below screenshot describes:

and provide some assertions to validate whether the command executed successfully or not.

and finally the expected body for the test case.

Now, if we execute this test case. Then the above REST API executed the command `echo hello` on the remote machine and returned the command output as response as shown in below figure.

Hope you got the idea.

Now, let us take a more practical example of using this utility. Suppose, I want to restore my MongoDB database before I execute my test suite. And my MongoDB dump is stored at {{dataDir}}/xyz-ts-dump directory. Then I can write a separate test case in vREST like below:

Similarly other details can be provided as described in previous example.

You can even execute some custom script via this API to initialize your Test Suite data depending upon your context.