-
Notifications
You must be signed in to change notification settings - Fork 322
Support skipping integration tests for unavailable CF features via environment variables #1346
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
base: main
Are you sure you want to change the base?
Changes from all commits
44bfb29
c0014e6
0a030e8
3efc897
5ad1072
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,7 @@ | |
| import org.cloudfoundry.client.v3.Metadata; | ||
| import org.cloudfoundry.client.v3.Relationship; | ||
| import org.cloudfoundry.client.v3.applications.Application; | ||
| import org.cloudfoundry.client.v3.applications.ApplicationResource; | ||
| import org.cloudfoundry.client.v3.applications.DeleteApplicationRequest; | ||
| import org.cloudfoundry.client.v3.applications.ListApplicationsRequest; | ||
| import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipRequest; | ||
|
|
@@ -129,6 +130,12 @@ final class CloudFoundryCleaner implements InitializingBean, DisposableBean { | |
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger("cloudfoundry-client.test"); | ||
|
|
||
| private static final boolean RUN_V2_CLEANUP = isRunV2Tests(); | ||
|
|
||
| private static boolean isRunV2Tests() { | ||
| return !"true".equalsIgnoreCase(System.getenv("SKIP_V2_TESTS")); | ||
| } | ||
|
Comment on lines
+133
to
+137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider putting this in |
||
|
|
||
| private static final Map<String, Boolean> STANDARD_FEATURE_FLAGS = | ||
| FluentMap.<String, Boolean>builder() | ||
| .entry("app_bits_upload", true) | ||
|
|
@@ -186,6 +193,32 @@ public void destroy() { | |
| } | ||
|
|
||
| void clean() { | ||
| if (!RUN_V2_CLEANUP) { | ||
| LOGGER.info("Skipping V2 API cleanup operations (SKIP_V2_TESTS=true)"); | ||
| // Only run V3 and UAA cleanup operations | ||
| Flux.empty() | ||
| .thenMany( | ||
| Mono.when( // No prerequisites - V3/UAA only | ||
| cleanClients(this.uaaClient, this.nameFactory), | ||
| cleanGroups(this.uaaClient, this.nameFactory), | ||
| cleanIdentityProviders(this.uaaClient, this.nameFactory), | ||
| cleanIdentityZones(this.uaaClient, this.nameFactory), | ||
| cleanUsersV3(this.cloudFoundryClient, this.nameFactory))) | ||
| .thenMany( | ||
| Mono.when( | ||
| cleanApplicationsV3( | ||
| this.cloudFoundryClient, | ||
| this.nameFactory, | ||
| false), // runV2Calls = false (V3-only path) | ||
| cleanUsers(this.uaaClient, this.nameFactory))) | ||
| .retryWhen(Retry.max(5).filter(SSLException.class::isInstance)) | ||
| .doOnSubscribe(s -> LOGGER.debug(">> CLEANUP (V3 only) <<")) | ||
| .doOnComplete(() -> LOGGER.debug("<< CLEANUP (V3 only) >>")) | ||
| .then() | ||
| .block(Duration.ofMinutes(30)); | ||
| return; | ||
| } | ||
|
|
||
| Flux.empty() | ||
| .thenMany( | ||
| Mono.when( // Before Routes | ||
|
|
@@ -218,7 +251,8 @@ void clean() { | |
| Mono.when( | ||
| cleanApplicationsV3( | ||
| this.cloudFoundryClient, | ||
| this.nameFactory), // After Routes, cannot run with | ||
| this.nameFactory, | ||
| true), // After Routes, cannot run with | ||
| // other cleanApps | ||
| cleanUsers(this.uaaClient, this.nameFactory) // After CF Users | ||
| )) | ||
|
|
@@ -241,32 +275,43 @@ void clean() { | |
| } | ||
|
|
||
| private static Flux<Void> cleanApplicationsV3( | ||
| CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { | ||
| return PaginationUtils.requestClientV3Resources( | ||
| page -> | ||
| cloudFoundryClient | ||
| .applicationsV3() | ||
| .list(ListApplicationsRequest.builder().page(page).build())) | ||
| .filter(application -> nameFactory.isApplicationName(application.getName())) | ||
| .delayUntil( | ||
| application -> | ||
| removeApplicationServiceBindings(cloudFoundryClient, application)) | ||
| .flatMap( | ||
| application -> | ||
| cloudFoundryClient | ||
| .applicationsV3() | ||
| .delete( | ||
| DeleteApplicationRequest.builder() | ||
| .applicationId(application.getId()) | ||
| .build()) | ||
| .then() | ||
| .doOnError( | ||
| t -> | ||
| LOGGER.error( | ||
| "Unable to delete V3 application" | ||
| + " {}", | ||
| application.getName(), | ||
| t))); | ||
| CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, boolean runV2Calls) { | ||
| Flux<ApplicationResource> apps = | ||
| PaginationUtils.requestClientV3Resources( | ||
| page -> | ||
| cloudFoundryClient | ||
| .applicationsV3() | ||
| .list( | ||
| ListApplicationsRequest.builder() | ||
| .page(page) | ||
| .build())) | ||
| .filter( | ||
| application -> | ||
| nameFactory.isApplicationName(application.getName())); | ||
|
|
||
| if (runV2Calls) { | ||
| apps = | ||
| apps.delayUntil( | ||
| application -> | ||
| removeApplicationServiceBindings( | ||
| cloudFoundryClient, application)); | ||
| } | ||
|
Comment on lines
+292
to
+298
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the only v2 calls, which lists then deletes service bindings. |
||
|
|
||
| return apps.flatMap( | ||
| application -> | ||
| cloudFoundryClient | ||
| .applicationsV3() | ||
| .delete( | ||
| DeleteApplicationRequest.builder() | ||
| .applicationId(application.getId()) | ||
| .build()) | ||
| .then() | ||
| .doOnError( | ||
| t -> | ||
| LOGGER.error( | ||
| "Unable to delete V3 application" + " {}", | ||
| application.getName(), | ||
| t))); | ||
| } | ||
|
|
||
| private static Flux<Void> cleanBuildpacks( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,7 @@ | |
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.DependsOn; | ||
|
|
@@ -350,6 +351,7 @@ RandomNameFactory nameFactory() { | |
|
|
||
| @Bean(initMethod = "block") | ||
| @DependsOn("cloudFoundryCleaner") | ||
| @ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's centralize this property name, e.g. in |
||
| Mono<String> metricRegistrarServiceInstance( | ||
| CloudFoundryClient cloudFoundryClient, Mono<String> spaceId, NameFactory nameFactory) { | ||
| return spaceId.flatMap( | ||
|
|
@@ -377,6 +379,7 @@ NetworkingClient networkingClient( | |
|
|
||
| @Bean(initMethod = "block") | ||
| @DependsOn("cloudFoundryCleaner") | ||
| @ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true) | ||
| Mono<String> organizationId( | ||
| CloudFoundryClient cloudFoundryClient, | ||
| String organizationName, | ||
|
|
@@ -516,6 +519,7 @@ String serviceName(NameFactory nameFactory) { | |
|
|
||
| @Bean(initMethod = "block") | ||
| @DependsOn("cloudFoundryCleaner") | ||
| @ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true) | ||
| Mono<String> spaceId( | ||
| CloudFoundryClient cloudFoundryClient, Mono<String> organizationId, String spaceName) { | ||
| return organizationId | ||
|
|
@@ -542,6 +546,7 @@ String spaceName(NameFactory nameFactory) { | |
|
|
||
| @Bean(initMethod = "block") | ||
| @DependsOn("cloudFoundryCleaner") | ||
| @ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true) | ||
| Mono<String> stackId(CloudFoundryClient cloudFoundryClient, Mono<String> stackName) { | ||
| return stackName | ||
| .flux() | ||
|
|
@@ -570,6 +575,7 @@ Mono<String> stackId(CloudFoundryClient cloudFoundryClient, Mono<String> stackNa | |
| */ | ||
| @Bean(initMethod = "block") | ||
| @DependsOn("cloudFoundryCleaner") | ||
| @ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true) | ||
| Mono<String> stackName(CloudFoundryClient cloudFoundryClient) { | ||
| return PaginationUtils.requestClientV2Resources( | ||
| page -> | ||
|
|
@@ -587,6 +593,7 @@ Mono<String> stackName(CloudFoundryClient cloudFoundryClient) { | |
| @Lazy | ||
| @Bean(initMethod = "block") | ||
| @DependsOn("cloudFoundryCleaner") | ||
| @ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true) | ||
| Mono<ApplicationUtils.ApplicationMetadata> testLogCacheApp( | ||
| CloudFoundryClient cloudFoundryClient, | ||
| Mono<String> spaceId, | ||
|
|
@@ -623,6 +630,7 @@ String testLogCacheAppName(NameFactory nameFactory) { | |
|
|
||
| @Lazy | ||
| @Bean | ||
| @ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true) | ||
| TestLogCacheEndpoints testLogCacheEndpoints( | ||
| ConnectionContext connectionContext, | ||
| TokenProvider tokenProvider, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2026 the original author or 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 org.cloudfoundry; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
| import org.junit.jupiter.api.extension.ExecutionCondition; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
|
||
| /** | ||
| * Annotation to mark tests that require browser-based authentication (e.g., OAuth | ||
| * authorization code grants, implicit grants). Tests annotated with this will be skipped | ||
| * if the environment variable {@code SKIP_BROWSER_AUTH_TESTS} is set to "true". | ||
| * | ||
| * <p>Usage: | ||
| * <pre> | ||
| * @RequiresBrowserAuth | ||
| * public class MyAuthTest extends AbstractIntegrationTest { | ||
| * // ... | ||
| * } | ||
| * </pre> | ||
| * | ||
| * <p>To skip browser auth tests, set the environment variable: | ||
| * <pre> | ||
| * export SKIP_BROWSER_AUTH_TESTS=true | ||
| * </pre> | ||
| */ | ||
| @Target({ElementType.METHOD, ElementType.TYPE}) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| @Inherited | ||
| @ExtendWith(RequiresBrowserAuth.BrowserAuthCondition.class) | ||
| public @interface RequiresBrowserAuth { | ||
|
|
||
| /** | ||
| * JUnit 5 ExecutionCondition that checks if Browser Auth tests should be skipped. | ||
| */ | ||
| class BrowserAuthCondition implements ExecutionCondition { | ||
|
|
||
| private static final String SKIP_BROWSER_AUTH_ENV = "SKIP_BROWSER_AUTH_TESTS"; | ||
|
|
||
| @Override | ||
| public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
| if ("true".equalsIgnoreCase(System.getenv(SKIP_BROWSER_AUTH_ENV))) { | ||
| return ConditionEvaluationResult.disabled( | ||
| "Tests requiring Browser Authentication are disabled via " | ||
| + SKIP_BROWSER_AUTH_ENV | ||
| + " environment variable"); | ||
| } | ||
|
|
||
| return ConditionEvaluationResult.enabled("Browser authentication tests are enabled"); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2026 the original author or 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 org.cloudfoundry; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
| import org.junit.jupiter.api.extension.ExecutionCondition; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
|
||
| /** | ||
| * Annotation to mark tests that require the Metric Registrar service to be available. | ||
| * Tests annotated with this will be skipped if the environment variable | ||
| * {@code SKIP_METRIC_REGISTRAR_TESTS} is set to "true". | ||
| * | ||
| * <p>Usage: | ||
| * <pre> | ||
| * @RequiresMetricRegistrar | ||
| * public class MetricTest extends AbstractIntegrationTest { | ||
| * // ... | ||
| * } | ||
| * </pre> | ||
| * | ||
| * <p>To skip metric registrar tests, set the environment variable: | ||
| * <pre> | ||
| * export SKIP_METRIC_REGISTRAR_TESTS=true | ||
| * </pre> | ||
| */ | ||
| @Target({ElementType.METHOD, ElementType.TYPE}) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| @Inherited | ||
| @ExtendWith(RequiresMetricRegistrar.RegistrarCondition.class) | ||
| public @interface RequiresMetricRegistrar { | ||
|
|
||
| /** | ||
| * JUnit 5 ExecutionCondition that checks if Metric Registrar tests should be skipped. | ||
| */ | ||
| class RegistrarCondition implements ExecutionCondition { | ||
|
|
||
| private static final String SKIP_REGISTRAR_ENV = "SKIP_METRIC_REGISTRAR_TESTS"; | ||
|
|
||
| @Override | ||
| public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
| if ("true".equalsIgnoreCase(System.getenv(SKIP_REGISTRAR_ENV))) { | ||
| return ConditionEvaluationResult.disabled( | ||
| "Tests requiring Metric Registrar Service are disabled via " | ||
| + SKIP_REGISTRAR_ENV | ||
| + " environment variable."); | ||
| } | ||
|
|
||
| return ConditionEvaluationResult.enabled("Metric Registrar tests are enabled"); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really about "non-interactive" environments? Do we support interactive environments in our tests? Or is it about some UAA configuration that has browser-based auth?