Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
Fix getAppVersion when the config file is missing (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewinci authored Oct 12, 2020
1 parent 9f66494 commit da078bf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/insulator/lib/update/VersionChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class VersionChecker(private val customJarPath: String? = null) {
}

fun getAppVersion(): Either<Throwable, String> {
val jarFolder = Paths.get(URLDecoder.decode(jarPath, "UTF-8")).parent.toAbsolutePath().toString()
val jarFolder = Paths.get(URLDecoder.decode(jarPath, "UTF-8")).parent?.toAbsolutePath()?.toString()
?: return FileNotFoundException().left()
val configPath = Paths.get(jarFolder, CONFIG_FILE_NAME).toAbsolutePath().toString()
return if (File(configPath).exists())
Properties()
Expand Down
17 changes: 1 addition & 16 deletions src/test/kotlin/insulator/lib/update/VersionCheckerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class VersionCheckerTest : FunSpec({
it.mockCurrentAppVersion("0.0.8")
val sampleMessage = Paths.get("src", "test", "resources", "githubResponseSample.json").toFile().readText()
it.mockHttpResponse(200, sampleMessage)

// act
val version = sut.getCurrentVersion()
// assert
Expand All @@ -37,10 +36,8 @@ class VersionCheckerTest : FunSpec({
it.mockCurrentAppVersion(mockVersion)
val sampleMessage = Paths.get("src", "test", "resources", "githubResponseSample.json").toFile().readText()
it.mockHttpResponse(200, sampleMessage)

// act
val version = sut.getCurrentVersion()

// assert
version shouldBeRight Version(mockVersion, null)
}
Expand All @@ -65,10 +62,8 @@ class VersionCheckerTest : FunSpec({
val sut = VersionChecker()
val sampleMessage = Paths.get("src", "test", "resources", "githubResponseSample.json").toFile().readText()
it.mockHttpResponse(200, sampleMessage)

// act
val latestVersion = sut.getLatestVersion()

// assert
latestVersion shouldBeRight it.mockRelease
}
Expand All @@ -79,10 +74,8 @@ class VersionCheckerTest : FunSpec({
// arrange
val sut = VersionChecker()
it.mockHttpResponse(500, """Internal server error""")

// act
val latestVersion = sut.getLatestVersion()

// assert
latestVersion shouldBeLeft {}
}
Expand All @@ -93,10 +86,8 @@ class VersionCheckerTest : FunSpec({
// arrange
val sut = VersionChecker()
it.mockHttpResponse(200, """Invalid json here""")

// act
val latestVersion = sut.getLatestVersion()

// assert
latestVersion shouldBeLeft {}
}
Expand All @@ -107,10 +98,8 @@ class VersionCheckerTest : FunSpec({
// arrange
val sut = VersionChecker()
it.mockHttpResponse(200, """{"error": "Json response changed"}""")

// act
val latestVersion = sut.getLatestVersion()

// assert
latestVersion shouldBeLeft {}
}
Expand All @@ -124,10 +113,8 @@ class VersionCheckerTest : FunSpec({
createNewFile()
writeText("invalid string in the config file")
}

// act
val latestVersion = sut.getAppVersion()

// assert
latestVersion shouldBeLeft {}
}
Expand All @@ -136,11 +123,9 @@ class VersionCheckerTest : FunSpec({
test("get app version with a missing config file return left") {
VersionCheckerTestFixture().use {
// arrange
val sut = VersionChecker(it.mockInsulatorConfigPath.toString())

val sut = VersionChecker("random_path")
// act
val latestVersion = sut.getAppVersion()

// assert
latestVersion shouldBeLeft {}
}
Expand Down

0 comments on commit da078bf

Please sign in to comment.