Makes management tags mutable.
fixes gh-415
This commit is contained in:
@@ -52,7 +52,7 @@ public class ConsulDiscoveryProperties {
|
||||
private boolean enabled = true;
|
||||
|
||||
/** Tags to use when registering management service */
|
||||
private List<String> managementTags = Arrays.asList(MANAGEMENT);
|
||||
private List<String> managementTags = new ArrayList<>();
|
||||
|
||||
/** Alternate server path to invoke for health checking */
|
||||
private String healthCheckPath = "/actuator/health";
|
||||
@@ -165,9 +165,12 @@ public class ConsulDiscoveryProperties {
|
||||
private Boolean healthCheckTlsSkipVerify;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private ConsulDiscoveryProperties() {}
|
||||
private ConsulDiscoveryProperties() {
|
||||
this.managementTags.add(MANAGEMENT);
|
||||
}
|
||||
|
||||
public ConsulDiscoveryProperties(InetUtils inetUtils) {
|
||||
this();
|
||||
this.hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
|
||||
this.ipAddress = this.hostInfo.getIpAddress();
|
||||
this.hostname = this.hostInfo.getHostname();
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@@ -23,7 +25,7 @@ public class ConsulDiscoveryPropertiesTests {
|
||||
private Map<String, String> datacenters = Collections.singletonMap(SERVICE_NAME_IN_MAP, MAP_DC);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
properties = new ConsulDiscoveryProperties(new InetUtils(new InetUtilsProperties()));
|
||||
properties.setDefaultQueryTag(DEFAULT_TAG);
|
||||
properties.setServerListQueryTags(serverListQueryTags);
|
||||
@@ -31,29 +33,36 @@ public class ConsulDiscoveryPropertiesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnsNullWhenNoDefaultAndNotInMap() throws Exception {
|
||||
public void testReturnsNullWhenNoDefaultAndNotInMap() {
|
||||
properties.setDefaultQueryTag(null);
|
||||
|
||||
assertNull(properties.getQueryTagForService(SERVICE_NAME_NOT_IN_MAP));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTagReturnsDefaultWhenNotInMap() throws Exception {
|
||||
public void testGetTagReturnsDefaultWhenNotInMap() {
|
||||
assertEquals(DEFAULT_TAG, properties.getQueryTagForService(SERVICE_NAME_NOT_IN_MAP));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTagReturnsMapValueWhenInMap() throws Exception {
|
||||
public void testGetTagReturnsMapValueWhenInMap() {
|
||||
assertEquals(MAP_TAG, properties.getQueryTagForService(SERVICE_NAME_IN_MAP));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDcReturnsNullWhenNotInMap() throws Exception {
|
||||
public void testGetDcReturnsNullWhenNotInMap() {
|
||||
assertNull(properties.getDatacenters().get(SERVICE_NAME_NOT_IN_MAP));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDcReturnsMapValueWhenInMap() throws Exception {
|
||||
public void testGetDcReturnsMapValueWhenInMap() {
|
||||
assertEquals(MAP_DC, properties.getDatacenters().get(SERVICE_NAME_IN_MAP));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddManagementTag() {
|
||||
properties.getManagementTags().add("newTag");
|
||||
assertThat(properties.getManagementTags())
|
||||
.containsOnly(ConsulDiscoveryProperties.MANAGEMENT, "newTag");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user