Skip to content

Commit f5ecb4a

Browse files
committed
Add ability to skip tests that require TCP routing
1 parent e340c95 commit f5ecb4a

5 files changed

Lines changed: 87 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ Name | Description
298298
`TEST_PROXY_USERNAME` | _(Optional)_ The username for a proxy to route all requests through
299299
`TEST_SKIPSSLVALIDATION` | _(Optional)_ Whether to skip SSL validation when connecting to the Cloud Foundry instance. Defaults to `false`.
300300
`UAA_API_REQUEST_LIMIT` | _(Optional)_ If your UAA server does rate limiting and returns 429 errors, set this variable to the smallest limit configured there. Whether your server limits UAA calls is shown in the log, together with the location of the configuration file on the server. Defaults to `0` (no limit).
301+
`SKIP_TCP_ROUTING_TESTS` | _(Optional)_ Set to `true` to skip TCP routing integration tests (TcpRoutesTest, RouterGroupsTest). Useful when the Cloud Foundry instance does not have TCP routing configured (i.e., no `routing_endpoint` in the info payload). Defaults to `false`.
301302
`SKIP_V2_TESTS` | _(Optional)_ Set to `true` to skip all V2 API integration tests. Useful when the Cloud Foundry V2 API is rate-limited or unavailable. When enabled, tests annotated with `@RequiresV2Api` will be skipped, including V3 tests that depend on V2 API calls (e.g., service broker creation). Defaults to `false`.
302303

303304
If you do not have access to a CloudFoundry instance with admin access, you can run one locally using [bosh-deployment](https://github.com/cloudfoundry/bosh-deployment) & [cf-deployment](https://github.com/cloudfoundry/cf-deployment/) and Virtualbox.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2026 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Inherited;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
26+
import org.junit.jupiter.api.extension.ExecutionCondition;
27+
import org.junit.jupiter.api.extension.ExtendWith;
28+
import org.junit.jupiter.api.extension.ExtensionContext;
29+
30+
/**
31+
* Annotation to mark tests that require TCP routing to be configured.
32+
*
33+
* <p>Tests annotated with this (or test classes containing this annotation)
34+
* will be skipped if the {@code SKIP_TCP_ROUTING_TESTS} environment variable
35+
* is set to "true".
36+
*
37+
* <p>Use this when your Cloud Foundry instance does not have TCP routing
38+
* configured (i.e., when the info payload does not contain a 'routing_endpoint' key).
39+
*
40+
* <p>Example usage:
41+
* <pre>
42+
* &#64;RequiresTcpRouting
43+
* public class TcpRoutesTest extends AbstractIntegrationTest {
44+
* // tests that require TCP routing
45+
* }
46+
* </pre>
47+
*/
48+
@Target({ElementType.METHOD, ElementType.TYPE})
49+
@Retention(RetentionPolicy.RUNTIME)
50+
@Documented
51+
@Inherited
52+
@ExtendWith(RequiresTcpRouting.SkipTcpRoutingCondition.class)
53+
public @interface RequiresTcpRouting {
54+
55+
/**
56+
* JUnit 5 ExecutionCondition that checks if tcp routing tests should be skipped.
57+
*/
58+
class SkipTcpRoutingCondition implements ExecutionCondition {
59+
60+
private static final String ENV_VAR = "SKIP_TCP_ROUTING_TESTS";
61+
62+
@Override
63+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
64+
String envValue = System.getenv(ENV_VAR);
65+
66+
if ("true".equalsIgnoreCase(envValue)) {
67+
return ConditionEvaluationResult.disabled(
68+
"TCP routing tests are disabled via "
69+
+ ENV_VAR
70+
+ " environment variable"
71+
+ ". TCP routing may not be configured on the target CF instance.");
72+
}
73+
74+
return ConditionEvaluationResult.enabled("TCP routing tests are enabled");
75+
}
76+
}
77+
}

integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.cloudfoundry.CleanupCloudFoundryAfterClass;
3030
import org.cloudfoundry.CloudFoundryVersion;
3131
import org.cloudfoundry.IfCloudFoundryVersion;
32+
import org.cloudfoundry.RequiresTcpRouting;
3233
import org.cloudfoundry.RequiresV2Api;
3334
import org.cloudfoundry.client.CloudFoundryClient;
3435
import org.cloudfoundry.logcache.v1.Envelope;
@@ -361,6 +362,7 @@ public void getManifest() throws IOException {
361362
}
362363

363364
@Test
365+
@RequiresTcpRouting
364366
public void getManifestForTcpRoute() throws IOException {
365367
String applicationName = this.nameFactory.getApplicationName();
366368

@@ -447,6 +449,7 @@ public void getStopped() throws IOException {
447449
}
448450

449451
@Test
452+
@RequiresTcpRouting
450453
public void getTcp() throws IOException {
451454
String applicationName = this.nameFactory.getApplicationName();
452455
String domainName = this.nameFactory.getDomainName();
@@ -1188,6 +1191,7 @@ public void pushRoutePath() throws IOException {
11881191
}
11891192

11901193
@Test
1194+
@RequiresTcpRouting
11911195
public void pushTcpRoute() throws IOException {
11921196
String applicationName = this.nameFactory.getApplicationName();
11931197
String domainName = this.nameFactory.getDomainName();
@@ -1311,6 +1315,7 @@ public void pushUpdateRoute() throws IOException {
13111315
}
13121316

13131317
@Test
1318+
@RequiresTcpRouting
13141319
public void pushUpdateTcpRoute() throws IOException {
13151320
String applicationName = this.nameFactory.getApplicationName();
13161321
String domainName = this.nameFactory.getDomainName();

integration-test/src/test/java/org/cloudfoundry/routing/v1/RouterGroupsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.time.Duration;
2020
import org.cloudfoundry.AbstractIntegrationTest;
21+
import org.cloudfoundry.RequiresTcpRouting;
2122
import org.cloudfoundry.routing.RoutingClient;
2223
import org.cloudfoundry.routing.v1.routergroups.ListRouterGroupsRequest;
2324
import org.cloudfoundry.routing.v1.routergroups.ListRouterGroupsResponse;
@@ -29,6 +30,7 @@
2930
import reactor.core.publisher.Mono;
3031
import reactor.test.StepVerifier;
3132

33+
@RequiresTcpRouting
3234
public final class RouterGroupsTest extends AbstractIntegrationTest {
3335

3436
private static final String DEFAULT_ROUTER_GROUP = "default-tcp";

integration-test/src/test/java/org/cloudfoundry/routing/v1/TcpRoutesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020
import org.cloudfoundry.AbstractIntegrationTest;
2121
import org.cloudfoundry.NameFactory;
22+
import org.cloudfoundry.RequiresTcpRouting;
2223
import org.cloudfoundry.routing.RoutingClient;
2324
import org.cloudfoundry.routing.v1.routergroups.ListRouterGroupsRequest;
2425
import org.cloudfoundry.routing.v1.routergroups.ListRouterGroupsResponse;
@@ -39,6 +40,7 @@
3940
import reactor.test.StepVerifier;
4041
import reactor.util.retry.Retry;
4142

43+
@RequiresTcpRouting
4244
public final class TcpRoutesTest extends AbstractIntegrationTest {
4345

4446
private static final String DEFAULT_ROUTER_GROUP = "default-tcp";

0 commit comments

Comments
 (0)