Skip to content

Commit

Permalink
Add architecture label check for SkipFor
Browse files Browse the repository at this point in the history
  • Loading branch information
dale-fu authored and mnovak1 committed Feb 23, 2022
1 parent 6a39fe3 commit 74857e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 11 additions & 3 deletions junit5/src/main/java/cz/xtf/junit5/annotations/SkipFor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,26 @@
/**
* Name or regexp pattern matching name of the image. For example "eap73-openjdk11-openshift-rhel8" or "eap73-openjdk11-.*"
* <p>
* Only one of {@code imageMetadataLabelName} and {@code name} can be presented.
* Only one of {@code name}, {@code imageMetadataLabelName} and {@code imageMetadataLabelArchitecture} can be presented.
*/
String name() default "";

/**
* Name or regexp pattern matching name in {@code Docker Labels} in image metadata
* For example "eap73-openjdk11-openshift-rhel8" or "eap73-openjdk11-.*".
* For example "jboss-eap-7/eap73-openjdk11-openshift-rhel8" or "eap73-openjdk11-.*".
* <p>
* Only one of {@code imageMetadataLabelName} and {@code name} can be presented.
* Only one of {@code name}, {@code imageMetadataLabelName} and {@code imageMetadataLabelArchitecture} can be presented.
*/
String imageMetadataLabelName() default "";

/**
* Architecture or regexp pattern matching architecture in {@code Docker Labels} in image metadata
* For example "x86_64" or "x86_.*".
* <p>
* Only one of {@code name}, {@code imageMetadataLabelName} and {@code imageMetadataLabelArchitecture} can be presented.
*/
String imageMetadataLabelArchitecture() default "";

String image();

String reason() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
}

public static ConditionEvaluationResult resolve(SkipFor skipFor) {
if (skipFor.name().equals("") == skipFor.imageMetadataLabelName().equals("")) {
if ((skipFor.name().equals("") == skipFor.imageMetadataLabelName().equals("") == skipFor
.imageMetadataLabelArchitecture().equals("")) ||
(!skipFor.name().equals("") && !skipFor.imageMetadataLabelName().equals("")
&& !skipFor.imageMetadataLabelArchitecture().equals(""))) {
throw new RuntimeException(
"Only one of 'name' and 'imageMetadataLabelName' can be presented in 'SkipFor' annotation.");
"Only one of 'name','imageMetadataLabelName' and 'imageMetadataLabelArchitecture' can be presented in 'SkipFor' annotation.");
}

Image image = Image.resolve(skipFor.image());
Matcher matcher;

if (!skipFor.name().equals("")) {
matcher = Pattern.compile(skipFor.name()).matcher(image.getRepo());
} else {
} else if (!skipFor.imageMetadataLabelName().equals("")) {
DockerImageMetadata metadata = DockerImageMetadata.get(OpenShifts.master(), image);
matcher = Pattern.compile(skipFor.imageMetadataLabelName()).matcher(metadata.labels().get("name"));
} else {
DockerImageMetadata metadata = DockerImageMetadata.get(OpenShifts.master(), image);
matcher = Pattern.compile(skipFor.imageMetadataLabelArchitecture()).matcher(metadata.labels().get("architecture"));
}

if (matcher.matches()) {
Expand Down

0 comments on commit 74857e5

Please sign in to comment.