diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt index 3be7065..8772647 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/Application.kt @@ -37,10 +37,6 @@ fun main(args: Array) { println("Config file not found. Please check if path is correct.") exitProcess(1) } - if (!(cmd as K3sCliCommand).isValidApplicationFileName()) { - println("Application file not found. Please check if path is correct.") - exitProcess(1) - } if (!cmd.isValidServerType()) { throw RuntimeException("Unknown serverType. Currently only k3s is accepted.") } 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 c5d39d9..9892aa9 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?): Boolean + fun exists(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 212fd99..8286060 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,9 +15,8 @@ fun Prov.provisionK3s(cli: K3sCliCommand) = task { // full k3s val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName) val repo: ApplicationFileRepository = DefaultApplicationFileRepository() - if(repo.exists(cli.applicationFileName)) { - provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName) - } + repo.exists(cli.applicationFileName) + provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName) } else if (cli.reprovision) { // TODO: Add logic that overrides config, when cmd option is set deprovisionK3sInfra() 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 89a67b0..488cf16 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt @@ -5,11 +5,11 @@ import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepos class DefaultApplicationFileRepository : ApplicationFileRepository { - override fun exists(applicationFileName: ApplicationFileName?): Boolean { - if (applicationFileName == null) { - return true + override fun exists(applicationFileName: ApplicationFileName?) { + if (applicationFileName != null) { + if (!genericFileExistenceCheck(applicationFileName.fullqualified())) { + throw RuntimeException("Application file not found. Please check if path is correct.") + } } - return genericFileExistenceCheck(applicationFileName.fileName) } - } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt new file mode 100644 index 0000000..0997684 --- /dev/null +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt @@ -0,0 +1,44 @@ +package org.domaindrivenarchitecture.provs.server.infrastructure + +import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName +import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository +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() { + //when + val invalidFileName: ApplicationFileName = ApplicationFileName("iDontExist") + val repo: ApplicationFileRepository = DefaultApplicationFileRepository() + + // then + val exception = assertThrows( + "Should not find the file." + ) { repo.exists(invalidFileName) } + + assertEquals( + "Application file not found. Please check if path is correct.", + exception.message) + } + + @Test + fun existsPasses() { + //when + val validFileName = "iExist" + File(validFileName).createNewFile() + + val validFile: ApplicationFileName = + ApplicationFileName(File(validFileName).absolutePath) + val repo: ApplicationFileRepository = DefaultApplicationFileRepository() + + // then + repo.exists(validFile) + + File(validFileName).deleteOnExit() + } +} \ No newline at end of file