Skip to content

Commit 5ea971f

Browse files
committed
Fix tests for Windows.
1 parent bad85c5 commit 5ea971f

19 files changed

Lines changed: 156 additions & 56 deletions

File tree

.github/workflows/maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
strategy:
2828
matrix:
2929
# Test against the LTS Java versions. TODO: add JDK18 when it becomes available.
30-
java: [ 8.0.x ]
31-
os: [ windows-latest, macos-latest, ubuntu-latest ]
30+
java: [ 8.0.x, 11.0.x, 17.0.x ]
31+
os: [ windows-latest, ubuntu-latest ]
3232
runs-on: ${{ matrix.os }}
3333
steps:
3434
- uses: actions/[email protected]

extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlApplyTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,22 @@
3838
public class KubectlApplyTest {
3939

4040
private static final String DISCOVERY_API =
41-
KubectlApplyTest.class.getClassLoader().getResource("discovery-api.json").getPath();
41+
new java.io.File(
42+
KubectlApplyTest.class.getClassLoader().getResource("discovery-api.json").getPath())
43+
.toString();
4244

4345
private static final String DISCOVERY_APIV1 =
44-
KubectlApplyTest.class.getClassLoader().getResource("discovery-api-v1.json").getPath();
46+
new java.io.File(
47+
KubectlApplyTest.class
48+
.getClassLoader()
49+
.getResource("discovery-api-v1.json")
50+
.getPath())
51+
.toString();
4552

4653
private static final String DISCOVERY_APIS =
47-
KubectlApplyTest.class.getClassLoader().getResource("discovery-apis.json").getPath();
54+
new java.io.File(
55+
KubectlApplyTest.class.getClassLoader().getResource("discovery-apis.json").getPath())
56+
.toString();
4857

4958
private ApiClient apiClient;
5059

extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlCreateTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.kubernetes.client.openapi.models.V1ConfigMap;
2222
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2323
import io.kubernetes.client.util.ClientBuilder;
24+
import java.io.File;
2425
import java.io.IOException;
2526
import java.nio.file.Files;
2627
import java.nio.file.Paths;
@@ -32,13 +33,21 @@
3233
public class KubectlCreateTest {
3334

3435
private static final String DISCOVERY_API =
35-
KubectlCreateTest.class.getClassLoader().getResource("discovery-api.json").getPath();
36+
new File(KubectlCreateTest.class.getClassLoader().getResource("discovery-api.json").getPath())
37+
.toString();
3638

3739
private static final String DISCOVERY_APIV1 =
38-
KubectlCreateTest.class.getClassLoader().getResource("discovery-api-v1.json").getPath();
40+
new File(
41+
KubectlCreateTest.class
42+
.getClassLoader()
43+
.getResource("discovery-api-v1.json")
44+
.getPath())
45+
.toString();
3946

4047
private static final String DISCOVERY_APIS =
41-
KubectlCreateTest.class.getClassLoader().getResource("discovery-apis.json").getPath();
48+
new File(
49+
KubectlCreateTest.class.getClassLoader().getResource("discovery-apis.json").getPath())
50+
.toString();
4251

4352
private ApiClient apiClient;
4453

extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlDrainTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.kubernetes.client.openapi.models.V1Pod;
3232
import io.kubernetes.client.util.ClientBuilder;
3333
import io.kubernetes.client.util.ModelMapper;
34+
import java.io.File;
3435
import java.io.IOException;
3536
import java.nio.file.Files;
3637
import java.nio.file.Paths;
@@ -41,7 +42,8 @@
4142
public class KubectlDrainTest {
4243

4344
private static final String POD_LIST_API =
44-
KubectlDrainTest.class.getClassLoader().getResource("pod-list.json").getPath();
45+
new File(KubectlDrainTest.class.getClassLoader().getResource("pod-list.json").getPath())
46+
.toString();
4547

4648
private ApiClient apiClient;
4749

extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlPatchTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.kubernetes.client.openapi.ApiClient;
2828
import io.kubernetes.client.openapi.models.V1ConfigMap;
2929
import io.kubernetes.client.util.ClientBuilder;
30+
import java.io.File;
3031
import java.io.IOException;
3132
import java.nio.file.Files;
3233
import java.nio.file.Paths;
@@ -37,13 +38,20 @@
3738
public class KubectlPatchTest {
3839

3940
private static final String DISCOVERY_API =
40-
KubectlPatchTest.class.getClassLoader().getResource("discovery-api.json").getPath();
41+
new File(KubectlPatchTest.class.getClassLoader().getResource("discovery-api.json").getPath())
42+
.toString();
4143

4244
private static final String DISCOVERY_APIV1 =
43-
KubectlPatchTest.class.getClassLoader().getResource("discovery-api-v1.json").getPath();
45+
new File(
46+
KubectlPatchTest.class
47+
.getClassLoader()
48+
.getResource("discovery-api-v1.json")
49+
.getPath())
50+
.toString();
4451

4552
private static final String DISCOVERY_APIS =
46-
KubectlPatchTest.class.getClassLoader().getResource("discovery-apis.json").getPath();
53+
new File(KubectlPatchTest.class.getClassLoader().getResource("discovery-apis.json").getPath())
54+
.toString();
4755

4856
private ApiClient apiClient;
4957

extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlRolloutTest.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import io.kubernetes.client.openapi.models.V1StatefulSetList;
3535
import io.kubernetes.client.util.ClientBuilder;
3636
import io.kubernetes.client.util.ModelMapper;
37+
import java.io.File;
3738
import java.io.IOException;
3839
import java.nio.file.Files;
3940
import java.nio.file.Paths;
@@ -50,34 +51,56 @@ public class KubectlRolloutTest {
5051
@Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
5152

5253
private static final String DEPLOYMENT =
53-
KubectlRolloutTest.class.getClassLoader().getResource("deployment.json").getPath();
54+
new File(KubectlRolloutTest.class.getClassLoader().getResource("deployment.json").getPath())
55+
.toString();
5456

5557
private static final String REPLICASET_LIST =
56-
KubectlRolloutTest.class.getClassLoader().getResource("replicaset-list.json").getPath();
58+
new File(
59+
KubectlRolloutTest.class
60+
.getClassLoader()
61+
.getResource("replicaset-list.json")
62+
.getPath())
63+
.toString();
5764

5865
private static final String DAEMON_SET =
59-
KubectlRolloutTest.class.getClassLoader().getResource("daemonset.json").getPath();
66+
new File(KubectlRolloutTest.class.getClassLoader().getResource("daemonset.json").getPath())
67+
.toString();
6068

6169
private static final String PATCHED_DAEMON_SET =
62-
KubectlRolloutTest.class.getClassLoader().getResource("patched-daemonset.json").getPath();
70+
new File(
71+
KubectlRolloutTest.class
72+
.getClassLoader()
73+
.getResource("patched-daemonset.json")
74+
.getPath())
75+
.toString();
6376

6477
private static final String DAEMON_SET_CONTROLLER_REVISION_LIST =
65-
KubectlRolloutTest.class
66-
.getClassLoader()
67-
.getResource("daemonset-controllerrevision-list.json")
68-
.getPath();
78+
new File(
79+
KubectlRolloutTest.class
80+
.getClassLoader()
81+
.getResource("daemonset-controllerrevision-list.json")
82+
.getPath())
83+
.toString();
6984

7085
private static final String STATEFUL_SET =
71-
KubectlRolloutTest.class.getClassLoader().getResource("statefulset.json").getPath();
86+
new File(KubectlRolloutTest.class.getClassLoader().getResource("statefulset.json").getPath())
87+
.toString();
7288

7389
private static final String PATCHED_STATEFUL_SET =
74-
KubectlRolloutTest.class.getClassLoader().getResource("patched-statefulset.json").getPath();
90+
new File(
91+
KubectlRolloutTest.class
92+
.getClassLoader()
93+
.getResource("patched-statefulset.json")
94+
.getPath())
95+
.toString();
7596

7697
private static final String STATEFUL_SET_CONTROLLER_REVISION_LIST =
77-
KubectlRolloutTest.class
78-
.getClassLoader()
79-
.getResource("statefulset-controllerrevision-list.json")
80-
.getPath();
98+
new File(
99+
KubectlRolloutTest.class
100+
.getClassLoader()
101+
.getResource("statefulset-controllerrevision-list.json")
102+
.getPath())
103+
.toString();
81104

82105
@Before
83106
public void setup() throws IOException {

extended/src/test/java/io/kubernetes/client/extended/kubectl/util/deployment/DeploymentHelperTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.kubernetes.client.openapi.models.V1ReplicaSet;
2929
import io.kubernetes.client.openapi.models.V1ReplicaSetList;
3030
import io.kubernetes.client.util.ClientBuilder;
31+
import java.io.File;
3132
import java.io.IOException;
3233
import java.nio.file.Files;
3334
import java.nio.file.Paths;
@@ -46,10 +47,16 @@ public class DeploymentHelperTest {
4647
@Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort(), false);
4748

4849
private static final String DEPLOYMENT =
49-
DeploymentHelperTest.class.getClassLoader().getResource("deployment.json").getPath();
50+
new File(DeploymentHelperTest.class.getClassLoader().getResource("deployment.json").getPath())
51+
.toString();
5052

5153
private static final String REPLICASET_LIST =
52-
DeploymentHelperTest.class.getClassLoader().getResource("replicaset-list.json").getPath();
54+
new File(
55+
DeploymentHelperTest.class
56+
.getClassLoader()
57+
.getResource("replicaset-list.json")
58+
.getPath())
59+
.toString();
5360

5461
@Before
5562
public void setup() throws IOException {

extended/src/test/java/io/kubernetes/client/extended/pager/PagerTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.kubernetes.client.openapi.models.V1Namespace;
3131
import io.kubernetes.client.openapi.models.V1NamespaceList;
3232
import io.kubernetes.client.util.ClientBuilder;
33+
import java.io.File;
3334
import java.io.IOException;
3435
import java.nio.file.Files;
3536
import java.nio.file.Paths;
@@ -46,15 +47,20 @@ public class PagerTest {
4647

4748
private ApiClient client;
4849
private static final String LIST_PAGE0_FILE_PATH =
49-
PagerTest.class.getClassLoader().getResource("namespace-list-pager0.json").getPath();
50+
new File(PagerTest.class.getClassLoader().getResource("namespace-list-pager0.json").getPath())
51+
.toString();
5052
private static final String LIST_PAGE1_FILE_PATH =
51-
PagerTest.class.getClassLoader().getResource("namespace-list-pager1.json").getPath();
53+
new File(PagerTest.class.getClassLoader().getResource("namespace-list-pager1.json").getPath())
54+
.toString();
5255
private static final String LIST_PAGE2_FILE_PATH =
53-
PagerTest.class.getClassLoader().getResource("namespace-list-pager2.json").getPath();
56+
new File(PagerTest.class.getClassLoader().getResource("namespace-list-pager2.json").getPath())
57+
.toString();
5458
private static final String LIST_STATUS_FILE_PATH =
55-
PagerTest.class.getClassLoader().getResource("status-400.json").getPath();
59+
new File(PagerTest.class.getClassLoader().getResource("status-400.json").getPath())
60+
.toString();
5661
private static final String STATUS_BAD_TOKEN_FILE_PATH =
57-
PagerTest.class.getClassLoader().getResource("bad-token-status.json").getPath();
62+
new File(PagerTest.class.getClassLoader().getResource("bad-token-status.json").getPath())
63+
.toString();
5864
@Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
5965

6066
@Before

spring/src/main/java/io/kubernetes/client/spring/extended/manifests/KubernetesFromYamlProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import io.kubernetes.client.spring.extended.manifests.annotation.FromYaml;
1616
import io.kubernetes.client.util.Yaml;
17+
import java.io.File;
1718
import java.io.IOException;
1819
import java.lang.reflect.Field;
1920
import java.nio.file.Files;
@@ -91,7 +92,8 @@ private Object loadFromYaml(String targetFilePath) {
9192
Path targetPath = Paths.get(targetFilePath);
9293
if (!Files.exists(Paths.get(targetFilePath))) { // checks if it exists on the machine
9394
// otherwise use load from classpath resources
94-
Path classPath = Paths.get(getClass().getClassLoader().getResource(targetFilePath).getPath());
95+
Path classPath =
96+
new File(getClass().getClassLoader().getResource(targetFilePath).getFile()).toPath();
9597
if (Files.exists(classPath)) { // use classpath it works
9698
targetPath = classPath;
9799
} else {

util/src/main/java/io/kubernetes/client/Copy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ public Future<Integer> copyFileToPodAsync(
411411

412412
private Process execCopyToPod(String namespace, String pod, String container, Path destPath)
413413
throws ApiException, IOException {
414+
// TODO: This assumes Linux and won't work on Windows Containers (for many reasons...)
414415
String parentPath = destPath.getParent() != null ? destPath.getParent().toString() : ".";
415416
parentPath = parentPath.replace("\\", "/");
416417
return this.exec(

0 commit comments

Comments
 (0)