From cfe5d48b8e2189b36b7bfa086997b7cfc4530567 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 30 Aug 2022 15:25:44 +0200 Subject: [PATCH] Refactorings --- .../server/domain/k3s/ApplicationFileRepository.kt | 2 +- .../provs/server/domain/k3s/K3sService.kt | 2 +- .../DefaultApplicationFileRepository.kt | 4 ++-- .../DefaultApplicationFileRepositoryKtTest.kt | 11 +++++------ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/ApplicationFileRepository.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/ApplicationFileRepository.kt index 9892aa9..9bce73e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/ApplicationFileRepository.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/ApplicationFileRepository.kt @@ -1,5 +1,5 @@ package org.domaindrivenarchitecture.provs.server.domain.k3s interface ApplicationFileRepository { - fun exists(applicationFileName: ApplicationFileName?) + fun assertExists(applicationFileName: ApplicationFileName?) } \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt index 23b03e7..015b673 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt @@ -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 { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt index 488cf16..6efd0fc 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt @@ -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.") } } } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt index 0997684..a663c67 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt @@ -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( "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() }