-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor enhancements to compatible test tranformations task (#112840)
This commit adds support to transform the value of the value field in the close_to assertion. For example, with the following configuration: tasks.named("yamlRestCompatTestTransform").configure({ task -> task.replaceValueInCloseTo("get.fields._routing", 9.5, "my test name") }) will transform the following in "my test name" from: close_to: { get.fields._routing: { value: 5.1, error: 0.00001 } } to close_to: { get.fields._routing: { value: 9.5, error: 0.00001 } } This commit also adds supports to specify a specific test name to apply the replaceIsTrue task configuration. Before this commit, you could replace the values in the is_true, but it only supported doing so for all tests subject to the configuration.
- Loading branch information
1 parent
d799fec
commit 2eb9274
Showing
6 changed files
with
185 additions
and
1 deletion.
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
46 changes: 46 additions & 0 deletions
46
...org/elasticsearch/gradle/internal/test/rest/transform/close_to/ReplaceValueInCloseTo.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,46 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.test.rest.transform.close_to; | ||
|
||
import com.fasterxml.jackson.databind.node.NumericNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import org.elasticsearch.gradle.internal.test.rest.transform.ReplaceByKey; | ||
import org.gradle.api.tasks.Internal; | ||
|
||
/** | ||
* Replaces the value of the `value` of a close_to assertion for a given sub-node. | ||
* For example: close_to: { get.fields._routing: { value: 5.1, error: 0.00001 } } | ||
* to close_to: { get.fields._routing: { value: 9.5, error: 0.00001 } } | ||
*/ | ||
public class ReplaceValueInCloseTo extends ReplaceByKey { | ||
|
||
public ReplaceValueInCloseTo(String replaceKey, NumericNode replacementNode) { | ||
this(replaceKey, replacementNode, null); | ||
} | ||
|
||
public ReplaceValueInCloseTo(String replaceKey, NumericNode replacementNode, String testName) { | ||
super(replaceKey, replaceKey, replacementNode, testName); | ||
} | ||
|
||
@Override | ||
@Internal | ||
public String getKeyToFind() { | ||
return "close_to"; | ||
} | ||
|
||
@Override | ||
public void transformTest(ObjectNode matchParent) { | ||
ObjectNode closeToNode = (ObjectNode) matchParent.get(getKeyToFind()); | ||
ObjectNode subNode = (ObjectNode) closeToNode.get(requiredChildKey()); | ||
subNode.remove("value"); | ||
subNode.set("value", getReplacementNode()); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
...lasticsearch/gradle/internal/test/rest/transform/close_to/ReplaceValueInCloseToTests.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,46 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.test.rest.transform.close_to; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.NumericNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
import org.elasticsearch.gradle.internal.test.rest.transform.AssertObjectNodes; | ||
import org.elasticsearch.gradle.internal.test.rest.transform.TransformTests; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ReplaceValueInCloseToTests extends TransformTests { | ||
|
||
private static final YAMLFactory YAML_FACTORY = new YAMLFactory(); | ||
private static final ObjectMapper MAPPER = new ObjectMapper(YAML_FACTORY); | ||
|
||
@Test | ||
public void testReplaceValue() throws Exception { | ||
String test_original = "/rest/transform/close_to/close_to_replace_original.yml"; | ||
List<ObjectNode> tests = getTests(test_original); | ||
|
||
String test_transformed = "/rest/transform/close_to/close_to_replace_transformed_value.yml"; | ||
List<ObjectNode> expectedTransformation = getTests(test_transformed); | ||
|
||
NumericNode replacementNode = MAPPER.convertValue(99.99, NumericNode.class); | ||
|
||
List<ObjectNode> transformedTests = transformTests( | ||
tests, | ||
Collections.singletonList(new ReplaceValueInCloseTo("aggregations.tsids.buckets.0.voltage.value", replacementNode, null)) | ||
); | ||
|
||
AssertObjectNodes.areEqual(transformedTests, expectedTransformation); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...d-tools-internal/src/test/resources/rest/transform/close_to/close_to_replace_original.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
close_to test: | ||
- do: | ||
search: | ||
index: test | ||
body: | ||
size: 0 | ||
aggs: | ||
tsids: | ||
terms: | ||
field: _tsid | ||
order: | ||
_key: asc | ||
aggs: | ||
voltage: | ||
avg: | ||
field: voltage | ||
|
||
- match: {hits.total.value: 4} | ||
- length: {aggregations.tsids.buckets: 2} | ||
- match: {aggregations.tsids.buckets.0.key: "KDODRmbj7vu4rLWvjrJbpUuaET_vOYoRw6ImzKEcF4sEaGKnXSaKfM0" } | ||
- match: {aggregations.tsids.buckets.0.doc_count: 2 } | ||
- close_to: {aggregations.tsids.buckets.0.voltage.value: { value: 6.7, error: 0.01 }} | ||
- match: { aggregations.tsids.buckets.1.key: "KDODRmbj7vu4rLWvjrJbpUvcUWJEddqA4Seo8jbBBBFxwC0lrefCb6A" } | ||
- match: {aggregations.tsids.buckets.1.doc_count: 2 } | ||
- close_to: {aggregations.tsids.buckets.1.voltage.value: { value: 7.30, error: 0.01 }} |
26 changes: 26 additions & 0 deletions
26
...nternal/src/test/resources/rest/transform/close_to/close_to_replace_transformed_value.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
close_to test: | ||
- do: | ||
search: | ||
index: test | ||
body: | ||
size: 0 | ||
aggs: | ||
tsids: | ||
terms: | ||
field: _tsid | ||
order: | ||
_key: asc | ||
aggs: | ||
voltage: | ||
avg: | ||
field: voltage | ||
|
||
- match: {hits.total.value: 4} | ||
- length: {aggregations.tsids.buckets: 2} | ||
- match: {aggregations.tsids.buckets.0.key: "KDODRmbj7vu4rLWvjrJbpUuaET_vOYoRw6ImzKEcF4sEaGKnXSaKfM0" } | ||
- match: {aggregations.tsids.buckets.0.doc_count: 2 } | ||
- close_to: {aggregations.tsids.buckets.0.voltage.value: { value: 99.99, error: 0.01 }} | ||
- match: { aggregations.tsids.buckets.1.key: "KDODRmbj7vu4rLWvjrJbpUvcUWJEddqA4Seo8jbBBBFxwC0lrefCb6A" } | ||
- match: {aggregations.tsids.buckets.1.doc_count: 2 } | ||
- close_to: {aggregations.tsids.buckets.1.voltage.value: { value: 7.30, error: 0.01 }} |