committed by
Spencer Gibb
parent
bc6fccd867
commit
b3aaf4e57a
@@ -0,0 +1,72 @@
|
||||
package org.springframework.cloud.kubernetes.config;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Ryan Dawson
|
||||
*/
|
||||
public class KubernetesConfigConfigurationTest {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void kubernetesWhenKubernetesDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=false");
|
||||
assertFalse(context.containsBean("configMapPropertySourceLocator"));
|
||||
assertFalse(context.containsBean("secretsPropertySourceLocator"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesWhenKubernetesConfigDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.config.enabled=false");
|
||||
assertFalse(context.containsBean("configMapPropertySourceLocator"));
|
||||
assertFalse(context.containsBean("secretsPropertySourceLocator"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void kubernetesDefaultEnabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=true");
|
||||
assertTrue(context.containsBean("configMapPropertySourceLocator"));
|
||||
assertTrue(context.containsBean("secretsPropertySourceLocator"));
|
||||
}
|
||||
|
||||
private void setup(String... env) {
|
||||
this.context = new SpringApplicationBuilder(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
KubernetesClientTestConfiguration.class,
|
||||
BootstrapConfiguration.class).web(org.springframework.boot.WebApplicationType.NONE)
|
||||
.properties(env).run();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class KubernetesClientTestConfiguration {
|
||||
|
||||
@Bean
|
||||
KubernetesClient kubernetesClient() {
|
||||
return mock(KubernetesClient.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,11 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(name="spring.cloud.kubernetes.enabled", matchIfMissing = true)
|
||||
public class KubernetesDiscoveryClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "spring.cloud.kubernetes.discovery.enabled",matchIfMissing = true)
|
||||
public DiscoveryClient discoveryClient(KubernetesClient client,
|
||||
KubernetesDiscoveryProperties properties) {
|
||||
return new KubernetesDiscoveryClient(client, properties);
|
||||
|
||||
@@ -50,6 +50,13 @@ public class KubernetesCatalogServicesWatchConfigurationTest {
|
||||
assertFalse(context.containsBean("kubernetesCatalogWatch"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesCatalogWatchWhenKubernetesDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=false");
|
||||
assertFalse(context.containsBean("kubernetesCatalogWatch"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void kubernetesCatalogWatchDefaultEnabled() throws Exception {
|
||||
setup();
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Ryan Dawson
|
||||
*/
|
||||
public class KubernetesDiscoveryConfigurationTest {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesDiscoveryDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.discovery.enabled=false","spring.cloud.kubernetes.discovery.catalog-services-watch.enabled=false");
|
||||
assertFalse(context.containsBean("discoveryClient"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesDiscoveryWhenKubernetesDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=false");
|
||||
assertFalse(context.containsBean("discoveryClient"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void kubernetesDiscoveryDefaultEnabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=true");
|
||||
assertTrue(context.containsBean("discoveryClient"));
|
||||
}
|
||||
|
||||
private void setup(String... env) {
|
||||
this.context = new SpringApplicationBuilder(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
KubernetesClientTestConfiguration.class,
|
||||
KubernetesDiscoveryClientAutoConfiguration.class).web(org.springframework.boot.WebApplicationType.NONE)
|
||||
.properties(env).run();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class KubernetesClientTestConfiguration {
|
||||
|
||||
@Bean
|
||||
KubernetesClient kubernetesClient() {
|
||||
return mock(KubernetesClient.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user