Recommended practice for testing a REST Action plugin


(Alex Klibisz) #1

I'm building a plugin that exposes three REST endpoints by inheriting from the BaseRestHandler. I need to run integration tests to check the endpoints' functionality by sending requests and inspecting the responses.

I've seen some examples of using YAML API specs (e.g. the carrot2 plugin), but I haven't been able to find any documentation on how to implement these tests. For example, I haven't been able to find any docs for the ESClientYamlSuiteTestCase class.

Moreover, the data being passed to/from my endpoints is such that building the request body and checking the response data would be much simpler to do programmatically than it would to define YAML files by hand.

So I'm leaning towards using Python to build requests, hit the endpoints, and check the responses. My main hesitation is that it wouldn't really integrate with the Gradle build setup. To test I would have to build the plugin, start an ES instance, install the plugin, and then run the tests. Of course that can be scripted, but it's still nice if this can leverage the existing Gradle setup.

Are there any guides to doing such integration testing? Is using Python for this purpose a decent approach? I appreciate any tips as I'm fairly new to plugin development for Elasticsearch.


(Alexander Reelsen) #2

you don't need to use YAML tests for integration testing, you can also write the tests in java. You can extend form ESRestTestCase, use the infrastructure to have access to a HTTP client and write java with regular asserts.

Plenty of qa tests do this, like this or this


(Alex Klibisz) #3

Thanks @spinscale, those look very helpful.

Perhaps this is a question for a separate thread, but could you help me understand how the tests are invoked when I'm using the Gradle Elasticsearch plugin (org.elasticsearch.gradle:build-tools:6.2.4)? I want to understand by what mechanism the tests are being run, but I can't seem to find any docs for that Gradle plugin. In my case I am using the same Gradle setup as your cookiecutter "ingest-awesome" example.


(Ivan Brusic) #4

There is no documentation for the gradle plugin, or any development task for that matter, in the official docs, but there is some stuff in the code. Take a look at the testing documentation: https://github.com/elastic/elasticsearch/blob/master/TESTING.asciidoc#testing-the-rest-layer

There is some documentation regarding YAML testing, but it was not visible enough, so I added those links in the testing page to the appropriate place. I have struggled with the same concepts as well. I have come to enjoy using the YAML tests over using Java classes.


(Alex Klibisz) #5

Thanks @Ivan the docs you linked are helpful.

Can you tell me how I can see logs from my endpoints while running the tests?

I can make a POST request to my plugin using the RestClient in an ESIntegTestCase class, but I cannot see any of the logging that happens in that endpoint's logic. I've spend over an hour now trying various logging configurations (including the ones on the page you linked), but the client keeps suppressing/redirecting the logs.


(system) #6

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.