Refactorings
This commit is contained in:
parent
7940d29169
commit
cfe5d48b8e
4 changed files with 9 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
|||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||
|
||||
interface ApplicationFileRepository {
|
||||
fun exists(applicationFileName: ApplicationFileName?)
|
||||
fun assertExists(applicationFileName: ApplicationFileName?)
|
||||
}
|
|
@ -15,7 +15,7 @@ fun Prov.provisionK3s(cli: K3sCliCommand) = task {
|
|||
// full k3s
|
||||
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
|
||||
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
|
||||
repo.exists(cli.applicationFileName)
|
||||
repo.assertExists(cli.applicationFileName)
|
||||
provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -5,10 +5,10 @@ import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepos
|
|||
|
||||
class DefaultApplicationFileRepository : ApplicationFileRepository {
|
||||
|
||||
override fun exists(applicationFileName: ApplicationFileName?) {
|
||||
override fun assertExists(applicationFileName: ApplicationFileName?) {
|
||||
if (applicationFileName != null) {
|
||||
if (!genericFileExistenceCheck(applicationFileName.fullqualified())) {
|
||||
throw RuntimeException("Application file not found. Please check if path is correct.")
|
||||
throw RuntimeException("Application file ${applicationFileName.fileName} not found. Please check if path is correct.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,11 @@ import org.junit.jupiter.api.Test
|
|||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
|
||||
internal class DefaultApplicationFileRepositoryKtTest {
|
||||
|
||||
@Test
|
||||
fun existsThrowsRuntimeException() {
|
||||
fun assertExistsThrowsRuntimeException() {
|
||||
//when
|
||||
val invalidFileName: ApplicationFileName = ApplicationFileName("iDontExist")
|
||||
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
|
||||
|
@ -19,15 +18,15 @@ internal class DefaultApplicationFileRepositoryKtTest {
|
|||
// then
|
||||
val exception = assertThrows<RuntimeException>(
|
||||
"Should not find the file."
|
||||
) { repo.exists(invalidFileName) }
|
||||
) { repo.assertExists(invalidFileName) }
|
||||
|
||||
assertEquals(
|
||||
"Application file not found. Please check if path is correct.",
|
||||
"Application file iDontExist not found. Please check if path is correct.",
|
||||
exception.message)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun existsPasses() {
|
||||
fun assertExistsPasses() {
|
||||
//when
|
||||
val validFileName = "iExist"
|
||||
File(validFileName).createNewFile()
|
||||
|
@ -37,7 +36,7 @@ internal class DefaultApplicationFileRepositoryKtTest {
|
|||
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
|
||||
|
||||
// then
|
||||
repo.exists(validFile)
|
||||
repo.assertExists(validFile)
|
||||
|
||||
File(validFileName).deleteOnExit()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue