# REST testing scripts

**URL:** <https://discuss.elastic.co/t/rest-testing-scripts/116908>\
**Category:** Elasticsearch\
**Created:** [January 24, 2018, 5:43pm UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908 "2018-01-24T17:43:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 24, 2018, 5:43pm UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908/1 "2018-01-24T17:43:33Z")

</div>

Working on some code that I would like to test via the REST layer. The  
default plugins are not loaded during integration testing, so when attempt  
to use put\_script:, I get the following error:

"unable to put stored script with unsupported lang [painless]"

Testing for painless and mustache, both scripts, occur within their  
respective modules, which load the plugin during testing. My feature is  
across all scripts, so adding tests to lang-painless or lang-mustache is  
not ideal. I now see why there was no testing done on the generic REST  
endpoint. 🙂 What would be the best way to test the ScriptService? This  
code is a feature for the elasticsearch repo, not external code.

Cheers,

Ivan

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 25, 2018, 8:51am UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908/2 "2018-01-25T08:51:12Z")

</div>

hey Ivan,

if you want to unit test, you need to create mocks/stubs for your services.

The other thing to do is write real integration tests, where you can fire up the elasticsearch cluster with the needed plugins enabled, and then you can either run YAML rest tests against this or write your own java test that uses HTTP.

--Alex

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [January 25, 2018, 6:53pm UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908/3 "2018-01-25T18:53:13Z")

</div>

Normally to test scripting features in core, we would use a MockScript. See uses of MockScriptEngine and MockScriptPlugin in various unit tests.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 25, 2018, 6:03pm UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908/4 "2018-01-25T18:03:16Z")

</div>

As I mentioned at the end of my post, I am testing code within the main  
Elasticsearch repo. Judging by the lack of rest tests for the get scripts  
endpoint, it seems like it is not possible via a workaround. For now, I put  
my tests in the lang-painless module even the the code/tests are  
independent of script language. Not sure that creating a module that  
contains nothing by tests for code in core would be a good idea.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [January 25, 2018, 9:46pm UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908/5 "2018-01-25T21:46:25Z")

</div>

@Ivan I think this is a deficiency in our current rest tests. We have the integ-test-zip distribution for the purpose of testing plugins as isolated as possible, but this also means the setup is less realistic. You could suggest in an issue that we run the rest tests (the server level ones, not individual plugins own rest tests) with the full zip distribution (which I would be in favor of, but we would need to move them around a bit as currently they are run inside the integ-test-zip project).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 25, 2018, 10:42pm UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908/6 "2018-01-25T22:42:47Z")

</div>

Thanks Ryan, the was my takeaway from exploring the code. Would hate to see  
another flurry of tests against a full distribution since the existing  
tests already kill my laptop as is! I cannot see this issue being very  
common, so do not think it should requiring such a refactoring right now. I  
always try to adhere to best practices and testing is one of them.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 22, 2018, 10:43pm UTC](https://discuss.elastic.co/t/rest-testing-scripts/116908/7 "2018-02-22T22:43:02Z")

</div>

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