Skip to content

Commit 521195d

Browse files
Artyom Gabeevspencergibb
authored andcommitted
Removes "://" from KubernetesServiceInstance.getScheme()
fixes gh-486
1 parent cc38faa commit 521195d

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesServiceInstance.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
*/
3232
public class KubernetesServiceInstance implements ServiceInstance {
3333

34-
private static final String HTTP_PREFIX = "http://";
34+
private static final String HTTP_PREFIX = "http";
3535

36-
private static final String HTTPS_PREFIX = "https://";
36+
private static final String HTTPS_PREFIX = "https";
37+
38+
private static final String DSL = "//";
3739

3840
private static final String COLN = ":";
3941

@@ -102,7 +104,8 @@ public boolean isSecure() {
102104
@Override
103105
public URI getUri() {
104106
StringBuilder sb = new StringBuilder();
105-
sb.append(getScheme()).append(getHost()).append(COLN).append(getPort());
107+
sb.append(getScheme()).append(COLN).append(DSL).append(getHost()).append(COLN)
108+
.append(getPort());
106109
return URI.create(sb.toString());
107110
}
108111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.discovery;
18+
19+
import java.util.Collections;
20+
21+
import io.fabric8.kubernetes.api.model.EndpointAddress;
22+
import io.fabric8.kubernetes.api.model.EndpointPort;
23+
import org.junit.Test;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
public class KubernetesServiceInstanceTests {
28+
29+
@Test
30+
public void schemeIsHttp() {
31+
assertServiceInstance(false);
32+
}
33+
34+
private KubernetesServiceInstance assertServiceInstance(boolean secure) {
35+
EndpointAddress address = new EndpointAddress();
36+
address.setIp("1.2.3.4");
37+
EndpointPort port = new EndpointPort();
38+
port.setPort(8080);
39+
KubernetesServiceInstance instance = new KubernetesServiceInstance("123",
40+
"myservice", address, port, Collections.emptyMap(), secure);
41+
42+
assertThat(instance.getInstanceId()).isEqualTo("123");
43+
assertThat(instance.getServiceId()).isEqualTo("myservice");
44+
assertThat(instance.getHost()).isEqualTo("1.2.3.4");
45+
assertThat(instance.getPort()).isEqualTo(8080);
46+
assertThat(instance.isSecure()).isEqualTo(secure);
47+
assertThat(instance.getScheme()).isEqualTo(secure ? "https" : "http");
48+
return instance;
49+
}
50+
51+
@Test
52+
public void schemeIsHttps() {
53+
assertServiceInstance(true);
54+
}
55+
56+
}

0 commit comments

Comments
 (0)