-
Notifications
You must be signed in to change notification settings - Fork 50
no-issue: disable tests conditionally when binary is not present #1191
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
Open
ricardozanini
wants to merge
6
commits into
serverlessworkflow:main
Choose a base branch
from
ricardozanini:check-python
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
209f7ad
no-issue: disable tests conditionally when binary is not present
ricardozanini 8d01f97
Remove utils
ricardozanini cff868e
Incorporating copilot comments
ricardozanini 113ce36
Check protoc via jar first
ricardozanini d29fef7
Adding Javi's comment
ricardozanini c56e238
Fixing leftovers
ricardozanini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
53 changes: 53 additions & 0 deletions
53
impl/test/src/test/java/io/serverlessworkflow/impl/test/junit/BinaryCheckUtil.java
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.test.junit; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ConcurrentMap; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public final class BinaryCheckUtil { | ||
|
|
||
| private static final ConcurrentMap<String, Boolean> BINARY_CHECKS = new ConcurrentHashMap<>(); | ||
|
|
||
| private BinaryCheckUtil() {} | ||
|
|
||
| public static boolean isBinaryAvailable(String... command) { | ||
| return BINARY_CHECKS.computeIfAbsent( | ||
| String.join(" ", command), | ||
| __ -> { | ||
| Process process; | ||
| try { | ||
| process = | ||
| new ProcessBuilder(command) | ||
| .redirectErrorStream(true) | ||
| .redirectOutput(ProcessBuilder.Redirect.DISCARD) | ||
| .start(); | ||
| } catch (IOException e) { | ||
| return false; | ||
| } | ||
| try { | ||
| return process.waitFor(2, TimeUnit.SECONDS) && process.exitValue() == 0; | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| return false; | ||
| } finally { | ||
| process.destroyForcibly(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...test/src/test/java/io/serverlessworkflow/impl/test/junit/DisabledIfProtocUnavailable.java
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.test.junit; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| @Target({ElementType.TYPE, ElementType.METHOD}) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @ExtendWith(ProtocCheckCondition.class) | ||
| public @interface DisabledIfProtocUnavailable {} |
27 changes: 27 additions & 0 deletions
27
...test/src/test/java/io/serverlessworkflow/impl/test/junit/DisabledIfPythonUnavailable.java
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.test.junit; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| @Target({ElementType.TYPE, ElementType.METHOD}) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @ExtendWith(PythonCheckCondition.class) | ||
| public @interface DisabledIfPythonUnavailable {} |
53 changes: 53 additions & 0 deletions
53
impl/test/src/test/java/io/serverlessworkflow/impl/test/junit/ProtocCheckCondition.java
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.test.junit; | ||
|
|
||
| import static io.serverlessworkflow.impl.test.junit.BinaryCheckUtil.isBinaryAvailable; | ||
|
|
||
| import com.github.os72.protocjar.Protoc; | ||
| import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
| import org.junit.jupiter.api.extension.ExecutionCondition; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
| import org.junit.platform.commons.util.AnnotationUtils; | ||
|
|
||
| public class ProtocCheckCondition implements ExecutionCondition { | ||
|
|
||
| private static boolean protocAvailable = false; | ||
|
|
||
| static { | ||
| try { | ||
| protocAvailable = Protoc.runProtoc(new String[] {"--version"}) == 0; | ||
| } catch (Exception e) { | ||
| // ignore | ||
| } | ||
| if (!protocAvailable) { | ||
| protocAvailable = isBinaryAvailable("protoc", "--version"); | ||
| } | ||
| } | ||
ricardozanini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
| return AnnotationUtils.findAnnotation(context.getElement(), DisabledIfProtocUnavailable.class) | ||
| .map( | ||
| annotation -> | ||
| protocAvailable | ||
ricardozanini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ? ConditionEvaluationResult.enabled( | ||
| "Protoc is available for the current platform.") | ||
| : ConditionEvaluationResult.disabled( | ||
| "Test disabled: Protoc not currently available not found.")) | ||
ricardozanini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .orElse(ConditionEvaluationResult.enabled("No @DisabledIfProtocUnavailable found.")); | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
impl/test/src/test/java/io/serverlessworkflow/impl/test/junit/PythonCheckCondition.java
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.test.junit; | ||
|
|
||
| import static io.serverlessworkflow.impl.test.junit.BinaryCheckUtil.isBinaryAvailable; | ||
|
|
||
| import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
| import org.junit.jupiter.api.extension.ExecutionCondition; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
| import org.junit.platform.commons.util.AnnotationUtils; | ||
|
|
||
| public class PythonCheckCondition implements ExecutionCondition { | ||
|
|
||
| @Override | ||
| public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
| return AnnotationUtils.findAnnotation(context.getElement(), DisabledIfPythonUnavailable.class) | ||
ricardozanini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .map( | ||
| annotation -> | ||
| isBinaryAvailable("python", "--version") | ||
| ? ConditionEvaluationResult.enabled("Python is available.") | ||
| : ConditionEvaluationResult.disabled("Test disabled: Python not found.")) | ||
| .orElse(ConditionEvaluationResult.enabled("No @DisabledIfBinaryUnavailable found.")); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.