Skip to content

Commit ac8289a

Browse files
Merge branch 'master' into 77031_occ_for_ingest_pipelines
2 parents 8c81989 + ea7d3f9 commit ac8289a

File tree

160 files changed

+4433
-1472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+4433
-1472
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/YamlRestCompatTestPluginFuncTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
196196
yamlRestTestImplementation "junit:junit:4.12"
197197
}
198198
tasks.named("yamlRestTestV${compatibleVersion}CompatTransform").configure({ task ->
199+
task.skipTest("test/test/two", "This is a test to skip test two")
199200
task.replaceValueInMatch("_type", "_doc")
200201
task.replaceValueInMatch("_source.values", ["z", "x", "y"], "one")
201202
task.removeMatch("_source.blah")
@@ -333,6 +334,9 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
333334
334335
---
335336
two:
337+
- skip:
338+
version: "all"
339+
reason: "This is a test to skip test two"
336340
- do:
337341
get:
338342
index: "test2"

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java

Lines changed: 123 additions & 20 deletions
Large diffs are not rendered by default.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.gradle.internal.test.rest.transform.skip;
10+
11+
import com.fasterxml.jackson.databind.JsonNode;
12+
import com.fasterxml.jackson.databind.node.ArrayNode;
13+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
14+
import com.fasterxml.jackson.databind.node.ObjectNode;
15+
import com.fasterxml.jackson.databind.node.TextNode;
16+
17+
import org.elasticsearch.gradle.internal.test.rest.transform.RestTestTransform;
18+
import org.elasticsearch.gradle.internal.test.rest.transform.RestTestTransformByParentObject;
19+
import org.elasticsearch.gradle.internal.test.rest.transform.RestTestTransformGlobalSetup;
20+
import org.elasticsearch.gradle.internal.test.rest.transform.feature.FeatureInjector;
21+
import org.gradle.api.tasks.Input;
22+
import org.gradle.api.tasks.Internal;
23+
import org.jetbrains.annotations.Nullable;
24+
25+
import java.util.Iterator;
26+
import java.util.Map;
27+
import java.util.Set;
28+
import java.util.function.Function;
29+
30+
/**
31+
* A {@link RestTestTransform} that injects a skip into a REST test.
32+
*/
33+
public class Skip implements RestTestTransformGlobalSetup, RestTestTransformByParentObject {
34+
35+
private static JsonNodeFactory jsonNodeFactory = JsonNodeFactory.withExactBigDecimals(false);
36+
37+
private final String skipReason;
38+
private final String testName;
39+
40+
public Skip(String testName, String skipReason) {
41+
this.skipReason = skipReason;
42+
this.testName = testName;
43+
}
44+
45+
public Skip(String skipReason) {
46+
this.skipReason = skipReason;
47+
this.testName = "";
48+
}
49+
50+
@Override
51+
public ObjectNode transformSetup(@Nullable ObjectNode setupNodeParent) {
52+
// only transform the global setup if there is no named test
53+
if (testName.isBlank()) {
54+
ArrayNode setupNode;
55+
if (setupNodeParent == null) {
56+
setupNodeParent = new ObjectNode(jsonNodeFactory);
57+
setupNode = new ArrayNode(jsonNodeFactory);
58+
setupNodeParent.set("setup", setupNode);
59+
}
60+
setupNode = (ArrayNode) setupNodeParent.get("setup");
61+
addSkip(setupNode);
62+
}
63+
return setupNodeParent;
64+
}
65+
66+
private void addSkip(ArrayNode skipParent) {
67+
Iterator<JsonNode> skipParentIt = skipParent.elements();
68+
boolean found = false;
69+
while (skipParentIt.hasNext()) {
70+
JsonNode arrayEntry = skipParentIt.next();
71+
if (arrayEntry.isObject()) {
72+
ObjectNode skipCandidate = (ObjectNode) arrayEntry;
73+
if (skipCandidate.get("skip") != null) {
74+
ObjectNode skipNode = (ObjectNode) skipCandidate.get("skip");
75+
skipNode.replace("version", TextNode.valueOf("all"));
76+
skipNode.replace("reason", TextNode.valueOf(skipReason));
77+
found = true;
78+
break;
79+
}
80+
}
81+
82+
}
83+
84+
if (found == false) {
85+
ObjectNode skipNode = new ObjectNode(jsonNodeFactory);
86+
skipParent.insert(0, skipNode);
87+
ObjectNode skipChild = new ObjectNode(jsonNodeFactory);
88+
skipChild.set("version", TextNode.valueOf("all"));
89+
skipChild.set("reason", TextNode.valueOf(skipReason));
90+
skipNode.set("skip", skipChild);
91+
}
92+
}
93+
94+
95+
@Override
96+
public void transformTest(ObjectNode parent) {
97+
if (testName.isBlank() == false) {
98+
assert parent.get(testName) instanceof ArrayNode;
99+
addSkip((ArrayNode) parent.get(testName));
100+
}
101+
}
102+
103+
@Override
104+
public String getKeyToFind() {
105+
return testName;
106+
}
107+
108+
@Input
109+
public String getSkipReason() {
110+
return skipReason;
111+
}
112+
113+
@Input
114+
public String getTestName() {
115+
return testName;
116+
}
117+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.gradle.internal.test.rest.transform.skip;
10+
11+
import com.fasterxml.jackson.databind.node.ObjectNode;
12+
13+
import org.elasticsearch.gradle.internal.test.rest.transform.AssertObjectNodes;
14+
import org.elasticsearch.gradle.internal.test.rest.transform.RestTestTransform;
15+
import org.elasticsearch.gradle.internal.test.rest.transform.TransformTests;
16+
import org.elasticsearch.gradle.internal.test.rest.transform.match.ReplaceKeyInMatch;
17+
import org.junit.Test;
18+
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
public class SkipTests extends TransformTests {
23+
24+
25+
@Test
26+
public void testAddGlobalSetup() throws Exception {
27+
String test_original = "/rest/transform/skip/without_setup_original.yml";
28+
List<ObjectNode> tests = getTests(test_original);
29+
30+
String test_transformed = "/rest/transform/skip/without_setup_transformed.yml";
31+
List<ObjectNode> expectedTransformation = getTests(test_transformed);
32+
33+
List<ObjectNode> transformedTests = transformTests(
34+
tests,
35+
Collections.singletonList(new Skip("my reason"))
36+
);
37+
38+
AssertObjectNodes.areEqual(transformedTests, expectedTransformation);
39+
}
40+
41+
@Test
42+
public void testModifyGlobalSetupWithSkip() throws Exception {
43+
String test_original = "/rest/transform/skip/without_setup_original.yml";
44+
List<ObjectNode> tests = getTests(test_original);
45+
46+
String test_transformed = "/rest/transform/skip/without_setup_transformed.yml";
47+
List<ObjectNode> expectedTransformation = getTests(test_transformed);
48+
49+
List<ObjectNode> transformedTests = transformTests(
50+
tests,
51+
Collections.singletonList(new Skip("my reason"))
52+
);
53+
54+
AssertObjectNodes.areEqual(transformedTests, expectedTransformation);
55+
}
56+
57+
@Test
58+
public void testModifyGlobalSetupWithoutSkip() throws Exception {
59+
String test_original = "/rest/transform/skip/with_setup_no_skip_original.yml";
60+
List<ObjectNode> tests = getTests(test_original);
61+
62+
String test_transformed = "/rest/transform/skip/with_setup_no_skip_transformed.yml";
63+
List<ObjectNode> expectedTransformation = getTests(test_transformed);
64+
65+
List<ObjectNode> transformedTests = transformTests(
66+
tests,
67+
Collections.singletonList(new Skip("my reason"))
68+
);
69+
70+
AssertObjectNodes.areEqual(transformedTests, expectedTransformation);
71+
}
72+
73+
@Test
74+
public void testModifyGlobalSetupWithFeatures() throws Exception {
75+
String test_original = "/rest/transform/skip/with_features_original.yml";
76+
List<ObjectNode> tests = getTests(test_original);
77+
78+
String test_transformed = "/rest/transform/skip/with_features_transformed.yml";
79+
List<ObjectNode> expectedTransformation = getTests(test_transformed);
80+
81+
List<ObjectNode> transformedTests = transformTests(
82+
tests,
83+
Collections.singletonList(new Skip("my reason"))
84+
);
85+
86+
AssertObjectNodes.areEqual(transformedTests, expectedTransformation);
87+
}
88+
89+
@Test
90+
public void testModifyPerTestSetup() throws Exception {
91+
String test_original = "/rest/transform/skip/per_test_original.yml";
92+
List<ObjectNode> tests = getTests(test_original);
93+
94+
String test_transformed = "/rest/transform/skip/per_test_transformed.yml";
95+
List<ObjectNode> expectedTransformation = getTests(test_transformed);
96+
97+
List<ObjectNode> transformedTests = transformTests(
98+
tests,
99+
List.of(new Skip("Two Test", "my reason"), new Skip("Three Test", "another reason"))
100+
);
101+
102+
AssertObjectNodes.areEqual(transformedTests, expectedTransformation);
103+
}
104+
105+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"One Test":
3+
- do:
4+
something:
5+
id: "something1"
6+
- match: { acknowledged: true }
7+
---
8+
"Two Test":
9+
- do:
10+
something:
11+
id: "something2"
12+
- match: { acknowledged: true }
13+
---
14+
"Three Test":
15+
- do:
16+
something:
17+
id: "something3"
18+
- match: { acknowledged: true }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
"One Test":
3+
- do:
4+
something:
5+
id: "something1"
6+
- match: { acknowledged: true }
7+
---
8+
"Two Test":
9+
- skip:
10+
version: "all"
11+
reason: "my reason"
12+
- do:
13+
something:
14+
id: "something2"
15+
- match: { acknowledged: true }
16+
---
17+
"Three Test":
18+
- skip:
19+
version: "all"
20+
reason: "another reason"
21+
- do:
22+
something:
23+
id: "something3"
24+
- match: { acknowledged: true }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
setup:
3+
- skip:
4+
features:
5+
- pre_existing_feature1
6+
- pre_existing_feature2
7+
---
8+
"Test with multiple feature setup":
9+
- do:
10+
something:
11+
id: "something"
12+
- match: { acknowledged: true }
13+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
setup:
3+
- skip:
4+
features:
5+
- pre_existing_feature1
6+
- pre_existing_feature2
7+
version: "all"
8+
reason: "my reason"
9+
---
10+
"Test with multiple feature setup":
11+
- do:
12+
something:
13+
id: "something"
14+
- match: { acknowledged: true }
15+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
setup:
3+
- do:
4+
some.setup:
5+
index: blah
6+
---
7+
"Test with setup but no skip (and by inference no features)":
8+
- do:
9+
something:
10+
id: "something"
11+
- match: { acknowledged: true }
12+
13+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
setup:
3+
- skip:
4+
version: "all"
5+
reason: "my reason"
6+
- do:
7+
some.setup:
8+
index: blah
9+
---
10+
"Test with setup but no skip (and by inference no features)":
11+
- do:
12+
something:
13+
id: "something"
14+
- match: { acknowledged: true }
15+
16+

0 commit comments

Comments
 (0)