From 56c34718510d54c1436efb8c0363582405543a30 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 28 Aug 2015 14:46:33 -0400 Subject: [PATCH] Fix test for _cat/nodeattrs Adds a node attribute to all test runs and uses the attribute to test `_cat/nodeattrs`. Note that its quite possible create an impressively slow regex while doing this and you have to be careful. See comment in commit for more if curious. Closes #12558 --- .../test/rest/ESRestTestCase.java | 1 + dev-tools/Elasticsearch.launch | 2 +- .../main/resources/ant/integration-tests.xml | 4 +- .../test/cat.nodeattrs/10_basic.yaml | 62 ++++++++++++++----- 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/test/rest/ESRestTestCase.java b/core/src/test/java/org/elasticsearch/test/rest/ESRestTestCase.java index f3e18d75124..33ddea019ae 100644 --- a/core/src/test/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -155,6 +155,7 @@ public abstract class ESRestTestCase extends ESIntegTestCase { return Settings.builder() .putArray(URLRepository.ALLOWED_URLS_SETTING, "http://snapshot.test*") .put(Node.HTTP_ENABLED, true) + .put("node.testattr", "test") .put(super.nodeSettings(nodeOrdinal)).build(); } diff --git a/dev-tools/Elasticsearch.launch b/dev-tools/Elasticsearch.launch index 2016518cd23..5995612c80b 100644 --- a/dev-tools/Elasticsearch.launch +++ b/dev-tools/Elasticsearch.launch @@ -14,5 +14,5 @@ - + diff --git a/dev-tools/src/main/resources/ant/integration-tests.xml b/dev-tools/src/main/resources/ant/integration-tests.xml index 23df37338de..f64f4403157 100644 --- a/dev-tools/src/main/resources/ant/integration-tests.xml +++ b/dev-tools/src/main/resources/ant/integration-tests.xml @@ -157,7 +157,7 @@ Starting up external cluster... - @@ -172,6 +172,8 @@ + + diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodeattrs/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodeattrs/10_basic.yaml index f076a3b1859..5f6e3e9ae09 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodeattrs/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodeattrs/10_basic.yaml @@ -1,30 +1,64 @@ --- -"Test cat nodes attrs output": - - - skip: - version: "all" - reason: "Waiting for #12558" - +"Help": - do: - cat.nodeattrs: {} + cat.nodeattrs: + help: true - match: $body: | - /((\S+)\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+(\S+)\s*)+/ + /^ node .+ \n + id .+ \n + pid .+ \n + host .+ \n + ip .+ \n + port .+ \n + attr .+ \n + value .+ \n + $/ + +--- +"Test cat nodes attrs output": + - do: + cat.nodeattrs: {} + - match: # All attributes look good + $body: | + /^# node\s+ host\s+ ip\s+ attr\s+ value\s* \n + (((\S+\s?){1,10})\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+ (\S+)\s* \n)+ + $/ + - match: # A specific planted attribute is present and looks good + $body: | + /# node\s+ host\s+ ip\s+ attr\s+ value\s* \n + ((\S+\s?){1,10})\s+ (\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+testattr\s+ test \s* \n + / + # Note for future editors: its quite possible to construct a regex with an + # intense amount of backtracking if you use something like (\S\s?)+ to match + # node name. - do: cat.nodeattrs: v: true - - - match: + - match: # All attributes look good including the heading $body: | - /((\S+)\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+(\S+)\s*)+/ + /^ node\s+ host\s+ ip\s+ attr\s+ value\s* \n + (((\S+\s?){1,10})\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+ (\S+)\s* \n)+ + $/ + - match: # A specific planted attribute is present and looks good + $body: | + /# node\s+ host\s+ ip\s+ attr\s+ value\s* \n + ((\S+\s?){1,10})\s+ (\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+testattr\s+ test \s* \n + / - do: cat.nodeattrs: h: attr,value v: true - - - match: + - match: # All attributes look good $body: | - /((\S+)\s+(\S+)\s*)+/ + /^ attr\s+ value\s*\n + ((\S+)\s+ (\S+)\s*)+ + $/ + - match: # A specific planted attribute is present and looks good + $body: | + /# attr\s+ value\s*\n + testattr\s+ test\s*\n + /