Cat API: Do not rely on hashmap for sorted entries
The tests for the recently added added wildcard feature were relying on order of the hashmap being used, which could be different. The implementation now ensures, that the header fields are parsed in the order they have been added.
This commit is contained in:
parent
ceb0782ebd
commit
9d5e789508
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
- match:
|
- match:
|
||||||
$body: |
|
$body: |
|
||||||
/^ bulk.max \s+ bulk.min \s+ \n
|
/^ bulk.min \s+ bulk.max \s+ \n
|
||||||
(\s+ \d+ \s+ \d+ \s+ \n)+ $/
|
(\s+ \d+ \s+ \d+ \s+ \n)+ $/
|
||||||
|
|
||||||
#(\s+ \d+ \s+ \d+ \n)+ $/
|
#(\s+ \d+ \s+ \d+ \n)+ $/
|
||||||
|
|
|
@ -157,16 +157,15 @@ public class RestTable {
|
||||||
private static Set<String> expandHeadersFromRequest(Table table, RestRequest request) {
|
private static Set<String> expandHeadersFromRequest(Table table, RestRequest request) {
|
||||||
Set<String> headers = new LinkedHashSet<>(table.getHeaders().size());
|
Set<String> headers = new LinkedHashSet<>(table.getHeaders().size());
|
||||||
|
|
||||||
Map<String, Table.Cell> headerMap = table.getHeaderMap();
|
|
||||||
// check headers and aliases
|
// check headers and aliases
|
||||||
for (String header : Strings.splitStringByCommaToArray(request.param("h"))) {
|
for (String header : Strings.splitStringByCommaToArray(request.param("h"))) {
|
||||||
if (Regex.isSimpleMatchPattern(header)) {
|
if (Regex.isSimpleMatchPattern(header)) {
|
||||||
for (Map.Entry<String, Table.Cell> configuredHeaderEntry : headerMap.entrySet()) {
|
for (Table.Cell tableHeaderCell : table.getHeaders()) {
|
||||||
String configuredHeader = configuredHeaderEntry.getKey();
|
String configuredHeader = tableHeaderCell.value.toString();
|
||||||
if (Regex.simpleMatch(header, configuredHeader)) {
|
if (Regex.simpleMatch(header, configuredHeader)) {
|
||||||
headers.add(configuredHeader);
|
headers.add(configuredHeader);
|
||||||
} else if (configuredHeaderEntry.getValue().attr.containsKey("alias")) {
|
} else if (tableHeaderCell.attr.containsKey("alias")) {
|
||||||
String[] aliases = Strings.splitStringByCommaToArray(configuredHeaderEntry.getValue().attr.get("alias"));
|
String[] aliases = Strings.splitStringByCommaToArray(tableHeaderCell.attr.get("alias"));
|
||||||
for (String alias : aliases) {
|
for (String alias : aliases) {
|
||||||
if (Regex.simpleMatch(header, alias)) {
|
if (Regex.simpleMatch(header, alias)) {
|
||||||
headers.add(configuredHeader);
|
headers.add(configuredHeader);
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class RestTableTest extends ElasticsearchTestCase {
|
||||||
List<RestTable.DisplayHeader> headers = buildDisplayHeaders(table, restRequest);
|
List<RestTable.DisplayHeader> headers = buildDisplayHeaders(table, restRequest);
|
||||||
|
|
||||||
List<String> headerNames = getHeaderNames(headers);
|
List<String> headerNames = getHeaderNames(headers);
|
||||||
assertThat(headerNames, containsInAnyOrder("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk"));
|
assertThat(headerNames, contains("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk"));
|
||||||
assertThat(headerNames, not(hasItem("unmatched")));
|
assertThat(headerNames, not(hasItem("unmatched")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class RestTableTest extends ElasticsearchTestCase {
|
||||||
List<RestTable.DisplayHeader> headers = buildDisplayHeaders(table, restRequest);
|
List<RestTable.DisplayHeader> headers = buildDisplayHeaders(table, restRequest);
|
||||||
|
|
||||||
List<String> headerNames = getHeaderNames(headers);
|
List<String> headerNames = getHeaderNames(headers);
|
||||||
assertThat(headerNames, containsInAnyOrder("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk"));
|
assertThat(headerNames, contains("bulk.foo", "bulk.bar", "aliasedBulk", "aliasedSecondBulk"));
|
||||||
assertThat(headerNames, not(hasItem("unmatched")));
|
assertThat(headerNames, not(hasItem("unmatched")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue