|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -83,29 +83,58 @@ void getActiveWhenHasHcLandscapeShouldReturnSap() {
|
83 | 83 | assertThat(platform.isActive(environment)).isTrue();
|
84 | 84 | }
|
85 | 85 |
|
| 86 | + @Test |
| 87 | + void getActiveWhenHasKubernetesServiceHostAndPortShouldReturnKubernetes() { |
| 88 | + Map<String, Object> envVars = new HashMap<>(); |
| 89 | + envVars.put("KUBERNETES_SERVICE_HOST", "---"); |
| 90 | + envVars.put("KUBERNETES_SERVICE_PORT", "8080"); |
| 91 | + Environment environment = getEnvironmentWithEnvVariables(envVars); |
| 92 | + CloudPlatform platform = CloudPlatform.getActive(environment); |
| 93 | + assertThat(platform).isEqualTo(CloudPlatform.KUBERNETES); |
| 94 | + assertThat(platform.isActive(environment)).isTrue(); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + void getActiveWhenHasKubernetesServiceHostAndNoKubernetesServicePortShouldNotReturnKubernetes() { |
| 99 | + Environment environment = getEnvironmentWithEnvVariables( |
| 100 | + Collections.singletonMap("KUBERNETES_SERVICE_HOST", "---")); |
| 101 | + CloudPlatform platform = CloudPlatform.getActive(environment); |
| 102 | + assertThat(platform).isNull(); |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + void getActiveWhenHasKubernetesServicePortAndNoKubernetesServiceHostShouldNotReturnKubernetes() { |
| 107 | + Environment environment = getEnvironmentWithEnvVariables( |
| 108 | + Collections.singletonMap("KUBERNETES_SERVICE_PORT", "8080")); |
| 109 | + CloudPlatform platform = CloudPlatform.getActive(environment); |
| 110 | + assertThat(platform).isNull(); |
| 111 | + } |
| 112 | + |
86 | 113 | @Test
|
87 | 114 | void getActiveWhenHasServiceHostAndServicePortShouldReturnKubernetes() {
|
88 |
| - MockEnvironment environment = new MockEnvironment(); |
89 |
| - Map<String, Object> source = new HashMap<>(); |
90 |
| - source.put("EXAMPLE_SERVICE_HOST", "---"); |
91 |
| - source.put("EXAMPLE_SERVICE_PORT", "8080"); |
92 |
| - PropertySource<?> propertySource = new SystemEnvironmentPropertySource( |
93 |
| - StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, source); |
94 |
| - environment.getPropertySources().addFirst(propertySource); |
| 115 | + Map<String, Object> envVars = new HashMap<>(); |
| 116 | + envVars.put("EXAMPLE_SERVICE_HOST", "---"); |
| 117 | + envVars.put("EXAMPLE_SERVICE_PORT", "8080"); |
| 118 | + Environment environment = getEnvironmentWithEnvVariables(envVars); |
95 | 119 | CloudPlatform platform = CloudPlatform.getActive(environment);
|
96 | 120 | assertThat(platform).isEqualTo(CloudPlatform.KUBERNETES);
|
97 | 121 | assertThat(platform.isActive(environment)).isTrue();
|
98 | 122 | }
|
99 | 123 |
|
100 | 124 | @Test
|
101 | 125 | void getActiveWhenHasServiceHostAndNoServicePortShouldNotReturnKubernetes() {
|
102 |
| - MockEnvironment environment = new MockEnvironment(); |
103 |
| - PropertySource<?> propertySource = new SystemEnvironmentPropertySource( |
104 |
| - StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, |
| 126 | + Environment environment = getEnvironmentWithEnvVariables( |
105 | 127 | Collections.singletonMap("EXAMPLE_SERVICE_HOST", "---"));
|
106 |
| - environment.getPropertySources().addFirst(propertySource); |
107 | 128 | CloudPlatform platform = CloudPlatform.getActive(environment);
|
108 | 129 | assertThat(platform).isNull();
|
109 | 130 | }
|
110 | 131 |
|
| 132 | + private Environment getEnvironmentWithEnvVariables(Map<String, Object> environmentVariables) { |
| 133 | + MockEnvironment environment = new MockEnvironment(); |
| 134 | + PropertySource<?> propertySource = new SystemEnvironmentPropertySource( |
| 135 | + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, environmentVariables); |
| 136 | + environment.getPropertySources().addFirst(propertySource); |
| 137 | + return environment; |
| 138 | + } |
| 139 | + |
111 | 140 | }
|
0 commit comments