From bc744e27c3323200ad598b518bf326b7f4750d82 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Fri, 8 Apr 2016 14:24:02 +0200 Subject: [PATCH] Monitoring: Fix MarvelTemplateUtilsTests.java on Windows This is due to line ending differences. Original commit: elastic/x-pack-elasticsearch@a5327cd3e6ae979bf49d1a93f4550b6e92640327 --- .../exporter/MarvelTemplateUtilsTests.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java index a44f92a3a0f..885c1ba9e0d 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/MarvelTemplateUtilsTests.java @@ -5,10 +5,13 @@ */ package org.elasticsearch.marvel.agent.exporter; +import org.apache.lucene.util.Constants; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.test.ESTestCase; +import org.hamcrest.Matcher; import org.junit.Rule; import org.junit.rules.ExpectedException; @@ -31,7 +34,7 @@ public class MarvelTemplateUtilsTests extends ESTestCase { assertThat(source, notNullValue()); assertThat(source.length(), greaterThan(0)); - assertThat(source, equalTo("{\n" + + assertThat(source, templateEqualTo("{\n" + " \"template\": \".monitoring-data-" + version + "\",\n" + " \"mappings\": {\n" + " \"type_1\": {\n" + @@ -76,17 +79,26 @@ public class MarvelTemplateUtilsTests extends ESTestCase { } public void testFilter() { - assertThat(MarvelTemplateUtils.filter(new BytesArray("${monitoring.template.version}"), 0), equalTo("0")); + assertThat(MarvelTemplateUtils.filter(new BytesArray("${monitoring.template.version}"), 0), templateEqualTo("0")); assertThat(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}\"}"), 1), - equalTo("{\"template\": \"test-1\"}")); + templateEqualTo("{\"template\": \"test-1\"}")); assertThat(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"${monitoring.template.version}-test\"}"), 2), - equalTo("{\"template\": \"2-test\"}")); + templateEqualTo("{\"template\": \"2-test\"}")); assertThat(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}-test\"}"), 3), - equalTo("{\"template\": \"test-3-test\"}")); + templateEqualTo("{\"template\": \"test-3-test\"}")); final int version = randomIntBetween(0, 100); assertThat(MarvelTemplateUtils.filter(new BytesArray("{\"foo-${monitoring.template.version}\": " + "\"bar-${monitoring.template.version}\"}"), version), - equalTo("{\"foo-" + version + "\": \"bar-" + version + "\"}")); + templateEqualTo("{\"foo-" + version + "\": \"bar-" + version + "\"}")); } + + public static Matcher templateEqualTo(String template) { + if (Constants.WINDOWS) { + // translate Windows line endings (\r\n) to standard ones (\n) + return equalTo(Strings.replace(template, System.lineSeparator(), "\n")); + } + return equalTo(template); + } + }