Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require 'capabilities' test runner feature if using capabilities check #108678

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Capabilities API":

- requires:
test_runner_features: [capabilities]
capabilities:
- method: GET
path: /_capabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ private static Stream<String> validateExecutableSections(
""", section.getLocation().lineNumber()))
);

if (hasCapabilitiesCheck(testSection, setupSection, teardownSection)
&& false == hasYamlRunnerFeature("capabilities", testSection, setupSection, teardownSection)) {
errors = Stream.concat(errors, Stream.of("""
attempted to add a [capabilities] check in prerequisites without a corresponding \
["requires": "test_runner_features": "capabilities"] \
so runners that do not support [capabilities] checks can skip the test"""));
}

return errors;
}

Expand All @@ -313,6 +321,16 @@ private static boolean hasYamlRunnerFeature(
|| (teardownSection != null && hasYamlRunnerFeature(feature, teardownSection.getPrerequisiteSection()));
}

private static boolean hasCapabilitiesCheck(
ClientYamlTestSection testSection,
SetupSection setupSection,
TeardownSection teardownSection
) {
return (testSection != null && testSection.getPrerequisiteSection().hasCapabilitiesCheck())
|| (setupSection != null && setupSection.getPrerequisiteSection().hasCapabilitiesCheck())
|| (teardownSection != null && teardownSection.getPrerequisiteSection().hasCapabilitiesCheck());
}

private static boolean hasYamlRunnerFeature(String feature, PrerequisiteSection prerequisiteSection) {
return prerequisiteSection != null && prerequisiteSection.hasYamlRunnerFeature(feature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.joining;
Expand Down Expand Up @@ -507,4 +508,9 @@ String buildMessage(String description, boolean isSkip) {
}
return messageBuilder.toString();
}

boolean hasCapabilitiesCheck() {
return Stream.concat(skipCriteriaList.stream(), requiresCriteriaList.stream())
.anyMatch(p -> p instanceof Prerequisites.CapabilitiesPredicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ static Predicate<ClientYamlTestExecutionContext> skipOnKnownIssue(List<KnownIssu
.anyMatch(i -> context.clusterHasFeature(i.clusterFeature()) && context.clusterHasFeature(i.fixedBy()) == false);
}

static Predicate<ClientYamlTestExecutionContext> requireCapabilities(List<CapabilitiesCheck> checks) {
static CapabilitiesPredicate requireCapabilities(List<CapabilitiesCheck> checks) {
// requirement not fulfilled if unknown / capabilities API not supported
return context -> checks.stream().allMatch(check -> checkCapabilities(context, check).orElse(false));
}

static Predicate<ClientYamlTestExecutionContext> skipCapabilities(List<CapabilitiesCheck> checks) {
static CapabilitiesPredicate skipCapabilities(List<CapabilitiesCheck> checks) {
// skip if unknown / capabilities API not supported
return context -> checks.stream().anyMatch(check -> checkCapabilities(context, check).orElse(true));
}

interface CapabilitiesPredicate extends Predicate<ClientYamlTestExecutionContext> {}

private static Optional<Boolean> checkCapabilities(ClientYamlTestExecutionContext context, CapabilitiesCheck check) {
Optional<Boolean> b = context.clusterHasCapabilities(check.method(), check.path(), check.parameters(), check.capabilities());
return b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ public void testSkipClusterFeaturesNoneToSkipMatch() {
"foobar",
emptyList()
);
assertFalse(section.hasCapabilitiesCheck());

var mockContext = mock(ClientYamlTestExecutionContext.class);
assertFalse(section.skipCriteriaMet(mockContext));
Expand All @@ -649,6 +650,7 @@ public void testSkipClusterFeaturesAllRequiredSomeToSkipMatch() {
"foobar",
emptyList()
);
assertFalse(section.hasCapabilitiesCheck());

var mockContext = mock(ClientYamlTestExecutionContext.class);
when(mockContext.clusterHasFeature("required-feature-1")).thenReturn(true);
Expand All @@ -667,6 +669,7 @@ public void testSkipClusterFeaturesAllRequiredNoneToSkipMatch() {
"foobar",
emptyList()
);
assertFalse(section.hasCapabilitiesCheck());

var mockContext = mock(ClientYamlTestExecutionContext.class);
when(mockContext.clusterHasFeature("required-feature-1")).thenReturn(true);
Expand All @@ -684,6 +687,7 @@ public void testSkipKnownIssue() {
"foobar",
emptyList()
);
assertFalse(section.hasCapabilitiesCheck());

var mockContext = mock(ClientYamlTestExecutionContext.class);
assertFalse(section.skipCriteriaMet(mockContext));
Expand Down Expand Up @@ -717,7 +721,7 @@ public void testEvaluateCapabilities() {
"required",
emptyList()
);

assertTrue(section.hasCapabilitiesCheck());
var context = mock(ClientYamlTestExecutionContext.class);

// when the capabilities API is unavailable:
Expand Down