Skip to content

Commit

Permalink
Merge pull request #25829 from jdubois
Browse files Browse the repository at this point in the history
* gh-25829:
  Polish "Add detection of Azure App Service to CloudPlatform"
  Add detection of Azure App Service to CloudPlatform

Closes gh-25829
  • Loading branch information
wilkinsona committed Apr 7, 2021
2 parents 660dc5f + 4d31182 commit 4d510d3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
Expand Down Expand Up @@ -130,6 +130,23 @@ private boolean isAutoDetected(EnumerablePropertySource<?> environmentPropertySo
return false;
}

},

/**
* Azure App Service platform.
*/
AZURE_APP_SERVICE {

private static final String WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME";

private static final String WEBSITES_ENABLE_APP_SERVICE_STORAGE = "WEBSITES_ENABLE_APP_SERVICE_STORAGE";

@Override
public boolean isDetected(Environment environment) {
return environment.containsProperty(WEBSITE_SITE_NAME)
&& environment.containsProperty(WEBSITES_ENABLE_APP_SERVICE_STORAGE);
}

};

private static final String PROPERTY_NAME = "spring.main.cloud-platform";
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
Expand Down Expand Up @@ -50,7 +50,6 @@ void getActiveWhenNotInCloudShouldReturnNull() {
Environment environment = new MockEnvironment();
CloudPlatform platform = CloudPlatform.getActive(environment);
assertThat(platform).isNull();

}

@Test
Expand Down Expand Up @@ -131,6 +130,32 @@ void getActiveWhenHasServiceHostAndNoServicePortShouldNotReturnKubernetes() {
assertThat(platform).isNull();
}

@Test
void getActiveWhenHasWebsiteSiteNameAndWebsitesEnableAppServiceStorageShouldReturnAzureAppService() {
Map<String, Object> envVars = new HashMap<>();
envVars.put("WEBSITE_SITE_NAME", "---");
envVars.put("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false");
Environment environment = getEnvironmentWithEnvVariables(envVars);
CloudPlatform platform = CloudPlatform.getActive(environment);
assertThat(platform).isEqualTo(CloudPlatform.AZURE_APP_SERVICE);
assertThat(platform.isActive(environment)).isTrue();
}

@Test
void getActiveWhenHasWebsiteSiteNameAndNoWebsitesEnableAppServiceStorageShouldNotReturnAzureAppService() {
Environment environment = getEnvironmentWithEnvVariables(Collections.singletonMap("WEBSITE_SITE_NAME", "---"));
CloudPlatform platform = CloudPlatform.getActive(environment);
assertThat(platform).isNull();
}

@Test
void getActiveWhenHasWebsitesEnableAppServiceStorageAndNoWebsiteNameShouldNotReturnAzureAppService() {
Environment environment = getEnvironmentWithEnvVariables(
Collections.singletonMap("WEBSITES_ENABLE_APP_SERVICE_STORAGE", "---"));
CloudPlatform platform = CloudPlatform.getActive(environment);
assertThat(platform).isNull();
}

@Test
void getActiveWhenHasEnforcedCloudPlatform() {
Environment environment = getEnvironmentWithEnvVariables(
Expand Down

0 comments on commit 4d510d3

Please sign in to comment.