diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/common/InstallParseBinariesTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/common/InstallParseBinariesTest.kt new file mode 100644 index 0000000000..15f1bbc3b6 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/common/InstallParseBinariesTest.kt @@ -0,0 +1,43 @@ +package ftl.ios.xctest.common + +import ftl.config.FtlConstants +import ftl.util.hasAllFiles +import org.junit.Assert.assertTrue +import org.junit.Assume.assumeTrue +import org.junit.Test +import java.nio.file.Paths + +internal class InstallParseBinariesTest { + + @Test + fun `should install binaries for windows`() { + // given + assumeTrue(FtlConstants.isWindows) + + // when + installBinaries + + // then + assertTrue( + Paths.get(FtlConstants.userHome, ".flank").toFile().hasAllFiles( + listOf("libatomic.so.1", "libatomic.so.1.2.0") + ) + ) + } + + @Test + fun `should install binaries for linux`() { + // given + assumeTrue(FtlConstants.isWindows.not() && FtlConstants.isMacOS.not()) + + // when + installBinaries + + // then + assertTrue( + Paths.get(FtlConstants.userHome, ".flank").toFile().hasAllFiles( + listOf("nm", "swift-demangle", "libatomic.so.1", "libatomic.so.1.2.0") + ) + ) + } +} diff --git a/test_runner/src/test/kotlin/ftl/util/FilesTest.kt b/test_runner/src/test/kotlin/ftl/util/FilesTest.kt new file mode 100644 index 0000000000..73ff6fdc45 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/util/FilesTest.kt @@ -0,0 +1,71 @@ +package ftl.util + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File +import java.nio.file.Files +import java.nio.file.Paths + +internal class FilesTest { + + @Test + fun `Should create symbolic file at desired location`() { + // given + val testFile = File.createTempFile("test", "file").toPath() + val expectedDestination = Paths.get(Files.createTempDirectory("temp").toString(), "test.link") + + // when + createSymbolicLink(expectedDestination, testFile) + + // then + assertTrue(Files.isSymbolicLink(expectedDestination)) + + // clean + testFile.toFile().delete() + expectedDestination.toFile().delete() + } + + @Test + fun `Should download file and store it and destination`() { + // given + val testSource = "https://github.com/Flank/flank/blob/master/settings.gradle.kts" + val testDestination = Paths.get(Files.createTempDirectory("temp").toString(), "settings.gradle.kts") + + // when + download(testSource, testDestination) + + // then + assertTrue(testDestination.toFile().exists()) + assertTrue(testDestination.toFile().length() > 0) + } + + @Test + fun `Should check if directory contains all needed files`() { + // given + val testDirectory = Files.createTempDirectory("test") + val testFiles = listOf( + Paths.get(testDirectory.toString(), "testFile1"), + Paths.get(testDirectory.toString(), "testFile2"), + Paths.get(testDirectory.toString(), "testFile3"), + Paths.get(testDirectory.toString(), "testFile4") + ) + + testFiles.forEach { Files.createFile(it) } + + // when + val resultTrue = testDirectory.toFile().hasAllFiles(testFiles.map { it.fileName.toString() }) + val resultFalse = testDirectory.toFile() + .hasAllFiles( + (testFiles + Paths.get(testDirectory.toString(), "testFile5")) + .map { it.fileName.toString() } + ) + + // then + assertTrue(resultTrue) + assertFalse(resultFalse) + + // clean + testDirectory.toFile().deleteRecursively() + } +}