File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/cloud
test/java/org/springframework/boot/cloud Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 2929 *
3030 * @author Phillip Webb
3131 * @author Brian Clozel
32+ * @author Nguyen Sach
3233 * @since 1.3.0
3334 */
3435public enum CloudPlatform {
@@ -157,7 +158,8 @@ public boolean isDetected(Environment environment) {
157158 * @return if the platform is active.
158159 */
159160 public boolean isActive (Environment environment ) {
160- return isEnforced (environment ) || isDetected (environment );
161+ String platformProperty = environment .getProperty (PROPERTY_NAME );
162+ return isEnforced (platformProperty ) || (platformProperty == null && isDetected (environment ));
161163 }
162164
163165 /**
Original file line number Diff line number Diff line change 1919import java .util .Collections ;
2020import java .util .HashMap ;
2121import java .util .Map ;
22+ import java .util .stream .Stream ;
2223
2324import org .junit .jupiter .api .Test ;
2425
3637 * Tests for {@link CloudPlatform}.
3738 *
3839 * @author Phillip Webb
40+ * @author Nguyen Sach
3941 */
4042class CloudPlatformTests {
4143
@@ -202,6 +204,16 @@ void isEnforcedWhenBinderPropertyIsMissingReturnsFalse() {
202204 assertThat (CloudPlatform .KUBERNETES .isEnforced (binder )).isFalse ();
203205 }
204206
207+ void isActiveWhenNoCloudPlatformIsEnforcedAndHasKubernetesServiceHostAndKubernetesServicePort () {
208+ Map <String , Object > envVars = new HashMap <>();
209+ envVars .put ("EXAMPLE_SERVICE_HOST" , "---" );
210+ envVars .put ("EXAMPLE_SERVICE_PORT" , "8080" );
211+ Environment environment = getEnvironmentWithEnvVariables (envVars );
212+ ((MockEnvironment ) environment ).setProperty ("spring.main.cloud-platform" , "none" );
213+ assertThat (Stream .of (CloudPlatform .values ()).filter ((platform ) -> platform .isActive (environment )))
214+ .containsExactly (CloudPlatform .NONE );
215+ }
216+
205217 private Environment getEnvironmentWithEnvVariables (Map <String , Object > environmentVariables ) {
206218 MockEnvironment environment = new MockEnvironment ();
207219 PropertySource <?> propertySource = new SystemEnvironmentPropertySource (
You can’t perform that action at this time.
0 commit comments