forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequireInProcess.java
More file actions
64 lines (56 loc) · 2.66 KB
/
Copy pathRequireInProcess.java
File metadata and controls
64 lines (56 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.e2e;
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;
/**
* Enables an annotated test class or method only when the E2E suite runs under
* the in-process (FFI) transport, i.e. when
* {@code COPILOT_SDK_DEFAULT_CONNECTION} is set to {@code inprocess}.
*
* <p>
* Use this for tests that require the real {@code runtime.node} native library
* to be present on the classpath, which only the {@code -Pinprocess} Maven
* profile guarantees (see {@link InProcessTransportIT}). Without this profile,
* standard {@code mvn verify} runs would fail with a
* {@code FileNotFoundException} because the classifier JAR providing
* {@code runtime.node} is not on the classpath.
* </p>
*
* <p>
* The inverse of {@link SkipInProcess}.
* </p>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@ExtendWith(RequireInProcess.Condition.class)
public @interface RequireInProcess {
/**
* Explains why the annotated test requires the in-process transport.
*
* @return the skip reason used when the in-process transport is not active
*/
String value() default "Requires the -Pinprocess Maven profile";
/**
* JUnit 5 execution condition backing {@link RequireInProcess}.
*/
public static final class Condition implements org.junit.jupiter.api.extension.ExecutionCondition {
private static final String DEFAULT_CONNECTION_ENV_VAR = "COPILOT_SDK_DEFAULT_CONNECTION";
@Override
public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(
org.junit.jupiter.api.extension.ExtensionContext context) {
String envValue = System.getenv(DEFAULT_CONNECTION_ENV_VAR);
if ("inprocess".equalsIgnoreCase(envValue)) {
return org.junit.jupiter.api.extension.ConditionEvaluationResult
.enabled("Running under the in-process transport");
}
String reason = context.getElement().map(element -> element.getAnnotation(RequireInProcess.class))
.map(RequireInProcess::value).orElse("Requires the -Pinprocess Maven profile");
return org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled(reason);
}
}
}