Skip to content

Commit 1e17bcd

Browse files
committed
runtime getLatestVersion() fix plus unit test
1 parent d2f66c3 commit 1e17bcd

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/main/java/org/myrobotlab/service/Runtime.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,13 @@ public static String getVersion() {
14871487
public static String getLatestVersion() {
14881488
String latest = "https://myrobotlab-repo.s3.us-east-1.amazonaws.com/latestVersion.txt";
14891489
byte[] b = Http.get(latest);
1490-
String version = (b == null) ? "unknown" : new String(b);
1491-
return version;
1490+
1491+
String v = "{\"tag_name\":\"unknown\"}";
1492+
if (b != null) {
1493+
v = new String(b);
1494+
}
1495+
Map githubVersion = (Map) CodecUtils.fromJson(v);
1496+
return ((String) githubVersion.get("tag_name")).replaceFirst("^v", "");
14921497
}
14931498

14941499
// FIXME - shouldn't this be in platform ???

src/test/java/org/myrobotlab/service/RuntimeTest.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.myrobotlab.service;
22

33
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
54
import static org.junit.Assert.assertTrue;
65

7-
import java.util.Date;
86
import java.util.List;
97
import java.util.Map;
108

@@ -101,7 +99,6 @@ public void testRuntimeLocale() {
10199
assertEquals("fr-FR", l.toString());
102100

103101
}
104-
105102

106103
@Test
107104
public void testGetDescribeMessage() {
@@ -113,4 +110,33 @@ public void testGetDescribeMessage() {
113110
assertEquals("Incorrect UUID in describe query", "testUUID", ((DescribeQuery) msg.data[1]).uuid);
114111
}
115112

113+
@Test
114+
public void testGetLatestVersion() {
115+
if (hasInternet()) {
116+
try {
117+
String latestVersion = Runtime.getLatestVersion();
118+
Assert.assertNotNull("Latest version should not be null", latestVersion);
119+
Assert.assertFalse("Latest version should not be empty", latestVersion.isEmpty());
120+
121+
// The version should not contain the leading 'v' since getLatestVersion
122+
// removes it
123+
Assert.assertFalse("Version should not start with 'v'", latestVersion.startsWith("v"));
124+
125+
// Version should follow semantic versioning pattern (x.y.z)
126+
String[] versionParts = latestVersion.split("\\.");
127+
Assert.assertTrue("Version should have at least 2 parts (major.minor)", versionParts.length >= 2);
128+
129+
log.info("Latest version retrieved: {}", latestVersion);
130+
} catch (Exception e) {
131+
// If remote service is unavailable, the method should still return
132+
// "unknown"
133+
// rather than throwing an exception
134+
log.error("testGetLatestVersion failed", e);
135+
Assert.fail("getLatestVersion should not throw exceptions, but return 'unknown' on failure");
136+
}
137+
} else {
138+
log.info("Skipping testGetLatestVersion - no internet connection");
139+
}
140+
}
141+
116142
}

0 commit comments

Comments
 (0)