Refactorings

This commit is contained in:
erik 2022-08-30 15:25:44 +02:00
parent 7940d29169
commit cfe5d48b8e
4 changed files with 9 additions and 10 deletions

View file

@ -1,5 +1,5 @@
package org.domaindrivenarchitecture.provs.server.domain.k3s package org.domaindrivenarchitecture.provs.server.domain.k3s
interface ApplicationFileRepository { interface ApplicationFileRepository {
fun exists(applicationFileName: ApplicationFileName?) fun assertExists(applicationFileName: ApplicationFileName?)
} }

View file

@ -15,7 +15,7 @@ fun Prov.provisionK3s(cli: K3sCliCommand) = task {
// full k3s // full k3s
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName) val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
val repo: ApplicationFileRepository = DefaultApplicationFileRepository() val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
repo.exists(cli.applicationFileName) repo.assertExists(cli.applicationFileName)
provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName) provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
} }
else { else {

View file

@ -5,10 +5,10 @@ import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepos
class DefaultApplicationFileRepository : ApplicationFileRepository { class DefaultApplicationFileRepository : ApplicationFileRepository {
override fun exists(applicationFileName: ApplicationFileName?) { override fun assertExists(applicationFileName: ApplicationFileName?) {
if (applicationFileName != null) { if (applicationFileName != null) {
if (!genericFileExistenceCheck(applicationFileName.fullqualified())) { 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.")
} }
} }
} }

View file

@ -6,12 +6,11 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import java.io.File import java.io.File
import java.nio.file.Paths
internal class DefaultApplicationFileRepositoryKtTest { internal class DefaultApplicationFileRepositoryKtTest {
@Test @Test
fun existsThrowsRuntimeException() { fun assertExistsThrowsRuntimeException() {
//when //when
val invalidFileName: ApplicationFileName = ApplicationFileName("iDontExist") val invalidFileName: ApplicationFileName = ApplicationFileName("iDontExist")
val repo: ApplicationFileRepository = DefaultApplicationFileRepository() val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
@ -19,15 +18,15 @@ internal class DefaultApplicationFileRepositoryKtTest {
// then // then
val exception = assertThrows<RuntimeException>( val exception = assertThrows<RuntimeException>(
"Should not find the file." "Should not find the file."
) { repo.exists(invalidFileName) } ) { repo.assertExists(invalidFileName) }
assertEquals( assertEquals(
"Application file not found. Please check if path is correct.", "Application file iDontExist not found. Please check if path is correct.",
exception.message) exception.message)
} }
@Test @Test
fun existsPasses() { fun assertExistsPasses() {
//when //when
val validFileName = "iExist" val validFileName = "iExist"
File(validFileName).createNewFile() File(validFileName).createNewFile()
@ -37,7 +36,7 @@ internal class DefaultApplicationFileRepositoryKtTest {
val repo: ApplicationFileRepository = DefaultApplicationFileRepository() val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
// then // then
repo.exists(validFile) repo.assertExists(validFile)
File(validFileName).deleteOnExit() File(validFileName).deleteOnExit()
} }