-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(show vespa version): show vespa version (#77)
- Loading branch information
1 parent
25f3188
commit b69816b
Showing
7 changed files
with
67 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.vispana.api.model; | ||
|
||
public record VespaVersion(long major, long minor, long patch) { | ||
|
||
public static VespaVersion fromString(String version) { | ||
|
||
// Vespa use semantic versioning major.minor.patch | ||
var parts = version.split("\\."); | ||
if (parts.length != 3) { | ||
throw new RuntimeException( | ||
String.format("Failed to parse vespa semantic version: %s", version)); | ||
} | ||
|
||
try { | ||
new VespaVersion( | ||
Long.parseLong(parts[0]), Long.parseLong(parts[1]), Long.parseLong(parts[2])); | ||
} catch (NumberFormatException e) { | ||
throw new RuntimeException( | ||
String.format("Failed to parse vespa version numbers: %s", version), e); | ||
} | ||
return new VespaVersion( | ||
Long.parseLong(parts[0]), Long.parseLong(parts[1]), Long.parseLong(parts[2])); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return major + "." + minor + "." + patch; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.vispana.api.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class VespaVersionTest { | ||
|
||
@Test | ||
void fromString() { | ||
var version = VespaVersion.fromString("7.1.0"); | ||
assertEquals(7, version.major()); | ||
assertEquals(1, version.minor()); | ||
assertEquals(0, version.patch()); | ||
assertEquals("7.1.0", version.toString()); | ||
} | ||
|
||
@Test | ||
void fromStringThrowsOnInvalidVersion() { | ||
assertThrows(RuntimeException.class, () -> VespaVersion.fromString("7.1")); | ||
assertThrows(RuntimeException.class, () -> VespaVersion.fromString("8.323.a")); | ||
} | ||
} |