Skip to content

Commit

Permalink
Merge pull request #60 from querqy/fix/versionInfo_backend
Browse files Browse the repository at this point in the history
Fix version parsing in backend for version patterns missing minor or build versions
  • Loading branch information
mkr authored Feb 22, 2021
2 parents b66d013 + 1e308bb commit eb6ef47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
20 changes: 7 additions & 13 deletions app/models/config/SmuiVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,12 @@ case class SmuiVersion(
object SmuiVersion extends Logging {

def parse(rawVersionString: String): Option[SmuiVersion] = {
val regExPattern = "([\\d]+).([\\d]+).([\\d]+)".r
Try({
val regExPattern(majorStr, minorStr, buildStr) = rawVersionString
// convert strings to Ints
SmuiVersion(
majorStr.toInt, minorStr.toInt, buildStr.toInt
)
}).toOption match {
case None => {
logger.error(s":: parse :: failed to parse rawVersionString = $rawVersionString")
None
}
case Some(version) => Some(version)
val Pattern = """^(\d+)(.\d+)?(.\d+)?$""".r
rawVersionString match {
case Pattern(major, null, null) => Some(SmuiVersion(major.toInt, 0, 0))
case Pattern(major, minor, null) => Some(SmuiVersion(major.toInt, minor.tail.toInt, 0))
case Pattern(major, minor, build) => Some(SmuiVersion(major.toInt, minor.tail.toInt, build.tail.toInt))
case _ => None
}
}

Expand Down Expand Up @@ -85,6 +78,7 @@ object SmuiVersion extends Logging {
} else {
rawVer1.get
})

parse(rawVer) match {
case None => {
logger.error(s":: unable to parse latest DockerHub version string for SMUI (rawVer = $rawVer)")
Expand Down
7 changes: 5 additions & 2 deletions test/models/config/SmuiVersionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ class SmuiVersionSpec extends FlatSpec with Matchers {

"SmuiVersion version parsing" should "return None for invalid strings" in {
SmuiVersion.parse("invalid") shouldEqual None
SmuiVersion.parse("1.0") shouldEqual None
SmuiVersion.parse("1.0.") shouldEqual None
SmuiVersion.parse("1") shouldEqual None
SmuiVersion.parse("1.") shouldEqual None
}

"SmuiVersion version parsing" should "fill missing values for minor or build versions" in {
SmuiVersion.parse("1") shouldEqual Some(SmuiVersion(1, 0, 0))
SmuiVersion.parse("1.0") shouldEqual Some(SmuiVersion(1, 0, 0))
}

"SmuiVersion for next deployment" should "be greater than latest version provided on DockerHub" in {

// TODO deal with local deployments, that do not necessarily come with an incremented version number
Expand Down

0 comments on commit eb6ef47

Please sign in to comment.