Skip to content

Commit 9fff736

Browse files
committed
Add a test for parsing wrong labels
1 parent 76aac38 commit 9fff736

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

kube/src/test/java/org/jgroups/ping/kube/test/ClientTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testPods() throws Exception {
5353
@Test
5454
public void testParsingPortWithoutNames() throws Exception {
5555
//given
56-
Client client = new TestClient("/pods_without_ports.json", 8888);
56+
Client client = new TestClient("pods_without_ports.json", 8888);
5757

5858
//when
5959
long numberOfPods = client.getPods(null, null).stream()
@@ -64,6 +64,18 @@ public void testParsingPortWithoutNames() throws Exception {
6464
assertEquals(2, numberOfPods);
6565
}
6666

67+
@Test
68+
public void testParsingJSONWithWrongLabels() throws Exception {
69+
//given
70+
Client client = new TestClient("pods_with_wrong_labels.json", 8888);
71+
72+
//when
73+
long numberOfPods = client.getPods("doesn't matter", "doesn't matter").size();
74+
75+
//then
76+
assertEquals(0, numberOfPods);
77+
}
78+
6779
@Test
6880
public void testAcceptingProperPort() throws Exception {
6981
//given

kube/src/test/java/org/jgroups/ping/kube/test/TestClient.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616

1717
package org.jgroups.ping.kube.test;
1818

19-
import static org.jgroups.ping.common.Utils.readFileToString;
20-
21-
import java.io.File;
2219
import java.io.IOException;
20+
import java.io.InputStream;
2321
import java.net.URISyntaxException;
24-
import java.util.HashMap;
25-
import java.util.Map;
2622

2723
import org.jboss.dmr.ModelNode;
2824
import org.jgroups.ping.kube.Client;
@@ -31,28 +27,26 @@
3127
* @author <a href="mailto:[email protected]">Ales Justin</a>
3228
*/
3329
public class TestClient extends Client {
34-
private final Map<String, String> OPS = new HashMap<>();
30+
31+
private final String file;
3532

3633
public TestClient() throws URISyntaxException, IOException {
3734
this(8888);
3835
}
3936

4037
public TestClient(int port) throws URISyntaxException, IOException {
41-
this("/pods.json", port);
38+
this("pods.json", port);
4239
}
4340

4441
public TestClient(String jsonFile, int port) throws URISyntaxException, IOException {
4542
super(null, null, 0, 0, 0, 0, null, port);
46-
String json = readFileToString(new File(TestClient.class.getResource(jsonFile).toURI()));
47-
OPS.put("pods", json);
43+
file = jsonFile;
4844
}
4945

5046
@Override
5147
protected ModelNode getNode(String op, String namespace, String labels) throws Exception {
52-
String value = OPS.get(op);
53-
if (value == null) {
54-
throw new IllegalStateException("No such op: " + op);
48+
try (InputStream stream = this.getClass().getClassLoader().getResourceAsStream(file)) {
49+
return ModelNode.fromJSONStream(stream);
5550
}
56-
return ModelNode.fromJSONString(value);
5751
}
5852
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"kind": "PodList",
3+
"apiVersion": "v1",
4+
"resourceVersion":"1524",
5+
"items": []
6+
}

0 commit comments

Comments
 (0)