|
| 1 | +package org.elasticsearch.gradle.doc; |
| 2 | + |
| 3 | +import org.elasticsearch.gradle.test.GradleUnitTestCase; |
| 4 | +import org.gradle.api.InvalidUserDataException; |
| 5 | +import org.junit.Rule; |
| 6 | +import org.junit.rules.ExpectedException; |
| 7 | + |
| 8 | +import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.replaceBlockQuote; |
| 9 | + |
| 10 | +public class RestTestFromSnippetsTaskTests extends GradleUnitTestCase { |
| 11 | + @Rule |
| 12 | + public ExpectedException expectedEx = ExpectedException.none(); |
| 13 | + |
| 14 | + public void testInvalidBlockQuote() { |
| 15 | + String input = "\"foo\": \"\"\"bar\""; |
| 16 | + expectedEx.expect(InvalidUserDataException.class); |
| 17 | + expectedEx.expectMessage("Invalid block quote starting at 7 in:\n" + input); |
| 18 | + replaceBlockQuote(input); |
| 19 | + } |
| 20 | + |
| 21 | + public void testSimpleBlockQuote() { |
| 22 | + assertEquals("\"foo\": \"bort baz\"", replaceBlockQuote("\"foo\": \"\"\"bort baz\"\"\"")); |
| 23 | + } |
| 24 | + |
| 25 | + public void testMultipleBlockQuotes() { |
| 26 | + assertEquals("\"foo\": \"bort baz\", \"bar\": \"other\"", |
| 27 | + replaceBlockQuote("\"foo\": \"\"\"bort baz\"\"\", \"bar\": \"\"\"other\"\"\"")); |
| 28 | + } |
| 29 | + |
| 30 | + public void testEscapingInBlockQuote() { |
| 31 | + assertEquals("\"foo\": \"bort\\\" baz\"", replaceBlockQuote("\"foo\": \"\"\"bort\" baz\"\"\"")); |
| 32 | + assertEquals("\"foo\": \"bort\\n baz\"", replaceBlockQuote("\"foo\": \"\"\"bort\n baz\"\"\"")); |
| 33 | + } |
| 34 | + |
| 35 | + public void testIsDocWriteRequest() { |
| 36 | + assertTrue((boolean) RestTestsFromSnippetsTask.shouldAddShardFailureCheck("doc-index/_search")); |
| 37 | + assertFalse((boolean) RestTestsFromSnippetsTask.shouldAddShardFailureCheck("_cat")); |
| 38 | + assertFalse((boolean) RestTestsFromSnippetsTask.shouldAddShardFailureCheck("_ml/datafeeds/datafeed-id/_preview")); |
| 39 | + } |
| 40 | +} |
0 commit comments