Skip to content

Commit 1f36093

Browse files
authored
Merge pull request #1233 from brendandburns/ports
Change a bunch of tests to use dynamic ports for wire mocks.
2 parents a05f944 + 071ef64 commit 1f36093

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

util/src/test/java/io/kubernetes/client/AttachTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
2020
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
2121
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
22+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
2223

2324
import com.github.tomakehurst.wiremock.junit.WireMockRule;
2425
import io.kubernetes.client.Attach.AttachResult;
@@ -38,12 +39,11 @@ public class AttachTest {
3839

3940
private ApiClient client;
4041

41-
private static final int PORT = 8089;
42-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
42+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
4343

4444
@Before
4545
public void setup() throws IOException {
46-
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
46+
client = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
4747

4848
namespace = "default";
4949
podName = "apod";

util/src/test/java/io/kubernetes/client/DiscoveryTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
*/
1313
package io.kubernetes.client;
1414

15-
import static com.github.tomakehurst.wiremock.client.WireMock.*;
16-
import static org.junit.Assert.*;
15+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
16+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
17+
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
18+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
19+
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
20+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
21+
import static org.junit.Assert.assertEquals;
1722

1823
import com.github.tomakehurst.wiremock.junit.WireMockRule;
1924
import io.kubernetes.client.openapi.ApiClient;
@@ -33,13 +38,11 @@ public class DiscoveryTest {
3338

3439
private ApiClient apiClient;
3540

36-
private static final int PORT = 8089;
37-
38-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
41+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
3942

4043
@Before
4144
public void setup() throws IOException {
42-
apiClient = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
45+
apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
4346
}
4447

4548
@Test

util/src/test/java/io/kubernetes/client/ExecTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
2020
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
2121
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
22+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
2223
import static org.junit.Assert.assertEquals;
2324

2425
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -58,12 +59,11 @@ public class ExecTest {
5859

5960
private ApiClient client;
6061

61-
private static final int PORT = 8089;
62-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
62+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
6363

6464
@Before
6565
public void setup() throws IOException {
66-
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
66+
client = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
6767

6868
namespace = "default";
6969
podName = "apod";

util/src/test/java/io/kubernetes/client/PodLogsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
2020
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
2121
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
22+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
2223
import static org.junit.Assert.assertEquals;
2324

2425
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -46,12 +47,11 @@ public class PodLogsTest {
4647

4748
private ApiClient client;
4849

49-
private static final int PORT = 8089;
50-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
50+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
5151

5252
@Before
5353
public void setup() throws IOException {
54-
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
54+
client = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
5555

5656
namespace = "default";
5757
podName = "apod";

util/src/test/java/io/kubernetes/client/PortForwardTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
2020
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
2121
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
22+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
2223
import static io.kubernetes.client.ExecTest.makeStream;
2324
import static org.junit.Assert.assertEquals;
2425
import static org.junit.Assert.assertNotNull;
@@ -45,20 +46,17 @@
4546
public class PortForwardTest {
4647
private String namespace;
4748
private String podName;
48-
private String container;
4949

5050
private ApiClient client;
5151

52-
private static final int PORT = 8089;
53-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
52+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
5453

5554
@Before
5655
public void setup() throws IOException {
57-
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
56+
client = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
5857

5958
namespace = "default";
6059
podName = "apod";
61-
container = "acontainer";
6260
}
6361

6462
@Test

0 commit comments

Comments
 (0)