Skip to content

Commit 79665c2

Browse files
authored
Merge pull request #1238 from sarveshkaushal/k-test
Removing static port in Junit tests
2 parents bb2accf + bc64af7 commit 79665c2

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

util/src/test/java/io/kubernetes/client/informer/impl/DefaultSharedIndexInformerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package io.kubernetes.client.informer.impl;
1414

1515
import static com.github.tomakehurst.wiremock.client.WireMock.*;
16+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
1617
import static org.junit.Assert.*;
1718

1819
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -43,12 +44,11 @@ public class DefaultSharedIndexInformerTest {
4344

4445
private ApiClient client;
4546

46-
private static final int PORT = 8089;
47-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
47+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
4848

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

5353
namespace = "default";
5454
podName = "apod";

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package io.kubernetes.client.util;
1414

1515
import static com.github.tomakehurst.wiremock.client.WireMock.*;
16+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
1617

1718
import com.github.tomakehurst.wiremock.junit.WireMockRule;
1819
import io.kubernetes.client.custom.V1Patch;
@@ -28,13 +29,12 @@
2829
public class PatchUtilsTest {
2930

3031
private ApiClient client;
31-
private static final int PORT = 8089;
3232

33-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
33+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
3434

3535
@Before
3636
public void setup() throws IOException {
37-
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
37+
client = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
3838
}
3939

4040
@Test

util/src/test/java/io/kubernetes/client/util/credentials/TokenFileAuthenticationTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package io.kubernetes.client.util.credentials;
1414

1515
import static com.github.tomakehurst.wiremock.client.WireMock.*;
16+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
1617

1718
import com.github.tomakehurst.wiremock.client.WireMock;
1819
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -35,12 +36,12 @@ public class TokenFileAuthenticationTest {
3536
private static final int PORT = 8089;
3637
private TokenFileAuthentication auth;
3738

38-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
39+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
3940

4041
@Before
4142
public void setup() throws IOException {
4243
final ApiClient client = new ApiClient();
43-
client.setBasePath("http://localhost:" + PORT);
44+
client.setBasePath("http://localhost:" + wireMockRule.port());
4445
this.auth = new TokenFileAuthentication(SERVICEACCOUNT_TOKEN1_PATH);
4546
this.auth.provide(client);
4647
Configuration.setDefaultApiClient(client);

util/src/test/java/io/kubernetes/client/util/version/VersionTest.java

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

2324
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -34,12 +35,11 @@ public class VersionTest {
3435

3536
private ApiClient client;
3637

37-
private static final int PORT = 8091;
38-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
38+
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
3939

4040
@Before
4141
public void setup() throws IOException {
42-
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
42+
client = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
4343
}
4444

4545
@Test

0 commit comments

Comments
 (0)