Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Adamczyk committed Dec 11, 2020
1 parent 93f9cbd commit 6f53eb2
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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")
)
)
}
}
71 changes: 71 additions & 0 deletions test_runner/src/test/kotlin/ftl/util/FilesTest.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 6f53eb2

Please # to comment.