-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support regex warnings via REST test transform (#70359)
This commit adds support to for injecting warnings_regex and allowed_warnings_regex via test transformations used by compatible testing. related: #69501 related: #69010
- Loading branch information
1 parent
3417684
commit fec4ee5
Showing
10 changed files
with
234 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...rg/elasticsearch/gradle/test/rest/transform/warnings/InjectAllowedWarningsRegexTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.test.rest.transform.warnings; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.elasticsearch.gradle.test.rest.transform.RestTestTransform; | ||
import org.elasticsearch.gradle.test.rest.transform.feature.InjectFeatureTests; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class InjectAllowedWarningsRegexTests extends InjectFeatureTests { | ||
|
||
Set<String> addWarnings = Set.of("added warning"); | ||
private static final String ALLOWED_WARNINGS_REGEX = "allowed_warnings_regex"; | ||
|
||
/** | ||
* test file does not any allowed warnings defined | ||
*/ | ||
@Test | ||
public void testInjectAllowedWarningsNoPreExisting() throws Exception { | ||
String testName = "/rest/transform/warnings/without_existing_warnings.yml"; | ||
List<ObjectNode> tests = getTests(testName); | ||
validateSetupDoesNotExist(tests); | ||
List<ObjectNode> transformedTests = transformTests(tests); | ||
printTest(testName, transformedTests); | ||
validateSetupAndTearDown(transformedTests); | ||
validateBodyHasWarnings(ALLOWED_WARNINGS_REGEX, transformedTests, addWarnings); | ||
} | ||
|
||
/** | ||
* test file has preexisting allowed warnings | ||
*/ | ||
@Test | ||
public void testInjectAllowedWarningsWithPreExisting() throws Exception { | ||
String testName = "/rest/transform/warnings/with_existing_allowed_warnings.yml"; | ||
List<ObjectNode> tests = getTests(testName); | ||
validateSetupExist(tests); | ||
validateBodyHasWarnings(ALLOWED_WARNINGS_REGEX, tests, Set.of("c", "d")); | ||
List<ObjectNode> transformedTests = transformTests(tests); | ||
printTest(testName, transformedTests); | ||
validateSetupAndTearDown(transformedTests); | ||
validateBodyHasWarnings(ALLOWED_WARNINGS_REGEX, tests, Set.of("c", "d")); | ||
validateBodyHasWarnings(ALLOWED_WARNINGS_REGEX, tests, addWarnings); | ||
} | ||
|
||
@Override | ||
protected List<String> getKnownFeatures() { | ||
return Collections.singletonList(ALLOWED_WARNINGS_REGEX); | ||
} | ||
|
||
@Override | ||
protected List<RestTestTransform<?>> getTransformations() { | ||
return Collections.singletonList(new InjectAllowedWarnings(true, new ArrayList<>(addWarnings))); | ||
} | ||
|
||
@Override | ||
protected boolean getHumanDebug() { | ||
return false; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
.../java/org/elasticsearch/gradle/test/rest/transform/warnings/InjectWarningsRegexTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.test.rest.transform.warnings; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.elasticsearch.gradle.test.rest.transform.RestTestTransform; | ||
import org.elasticsearch.gradle.test.rest.transform.feature.InjectFeatureTests; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class InjectWarningsRegexTests extends InjectFeatureTests { | ||
|
||
private static final String WARNINGS_REGEX = "warnings_regex"; | ||
Set<String> addWarnings = Set.of("added warning"); | ||
|
||
/** | ||
* inject warning requires a test name to insert | ||
*/ | ||
@Test | ||
public void testInjectWarningsRequiresTestName() throws Exception { | ||
String testName = "/rest/transform/warnings/without_existing_warnings.yml"; | ||
List<ObjectNode> tests = getTests(testName); | ||
validateSetupDoesNotExist(tests); | ||
assertEquals( | ||
"inject warnings is only supported for named tests", | ||
expectThrows( | ||
NullPointerException.class, | ||
() -> transformTests(tests, Collections.singletonList(new InjectWarnings(new ArrayList<>(addWarnings), null))) | ||
).getMessage() | ||
); | ||
} | ||
|
||
/** | ||
* test file does not any warnings defined | ||
*/ | ||
@Test | ||
public void testInjectWarningsNoPreExisting() throws Exception { | ||
String testName = "/rest/transform/warnings/without_existing_warnings.yml"; | ||
List<ObjectNode> tests = getTests(testName); | ||
validateSetupDoesNotExist(tests); | ||
List<ObjectNode> transformedTests = transformTests(tests); | ||
printTest(testName, transformedTests); | ||
validateSetupAndTearDown(transformedTests); | ||
validateBodyHasWarnings(WARNINGS_REGEX, "Test warnings", transformedTests, addWarnings); | ||
validateBodyHasNoWarnings(WARNINGS_REGEX, "Test another", transformedTests); | ||
} | ||
|
||
/** | ||
* test file has preexisting warnings | ||
*/ | ||
@Test | ||
public void testInjectWarningsWithPreExisting() throws Exception { | ||
String testName = "/rest/transform/warnings/with_existing_warnings.yml"; | ||
List<ObjectNode> tests = getTests(testName); | ||
validateSetupExist(tests); | ||
validateBodyHasWarnings(WARNINGS_REGEX, tests, Set.of("c", "d")); | ||
List<ObjectNode> transformedTests = transformTests(tests); | ||
printTest(testName, transformedTests); | ||
validateSetupAndTearDown(transformedTests); | ||
validateBodyHasWarnings(WARNINGS_REGEX, tests, Set.of("c", "d")); | ||
validateBodyHasWarnings(WARNINGS_REGEX, "Test warnings", tests, addWarnings); | ||
} | ||
|
||
@Override | ||
protected List<String> getKnownFeatures() { | ||
return Collections.singletonList(WARNINGS_REGEX); | ||
} | ||
|
||
@Override | ||
protected List<RestTestTransform<?>> getTransformations() { | ||
return Collections.singletonList(new InjectWarnings(true, new ArrayList<>(addWarnings), "Test warnings")); | ||
} | ||
|
||
@Override | ||
protected boolean getHumanDebug() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
buildSrc/src/test/resources/rest/transform/warnings/with_existing_allowed_warnings.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.