1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

Fully cover RealFileSystem

This commit is contained in:
2022-11-09 20:05:15 +01:00
parent fa5c843619
commit a801174f0a

View File

@ -36,6 +36,30 @@ class RealFileSystemTest: XCTestCase {
XCTAssertFalse(FileSystem.fileExists(temporaryDirectory))
}
func test_directory_can_be_created_symlinked_and_read() {
let temporaryDirectory = self.createUniqueTemporaryDirectory()
let folderPath = "\(temporaryDirectory)/brew/etc/lib/c"
try! FileSystem.createDirectory(folderPath, withIntermediateDirectories: true)
XCTAssertTrue(FileSystem.directoryExists("\(temporaryDirectory)/brew"))
XCTAssertTrue(FileSystem.directoryExists("\(temporaryDirectory)/brew/etc"))
XCTAssertTrue(FileSystem.directoryExists("\(temporaryDirectory)/brew/etc/lib"))
XCTAssertTrue(FileSystem.directoryExists("\(temporaryDirectory)/brew/etc/lib/c"))
_ = system("ln -s \(temporaryDirectory)/brew/etc/lib/c \(temporaryDirectory)/c")
XCTAssertTrue(FileSystem.directoryExists("\(temporaryDirectory)/c"))
XCTAssertTrue(FileSystem.isSymlink("\(temporaryDirectory)/c"))
XCTAssertEqual(
try! FileSystem.getDestinationOfSymlink("\(temporaryDirectory)/c"),
"\(temporaryDirectory)/brew/etc/lib/c"
)
let contents = try! FileSystem.getShallowContentsOfDirectory("\(temporaryDirectory)/brew/etc/lib/c")
XCTAssertEqual([], contents)
}
private func createTestBinaryFile(_ temporaryDirectory: String) -> String {
let executablePath = "\(temporaryDirectory)/exec.sh"
@ -47,6 +71,21 @@ class RealFileSystemTest: XCTestCase {
return executablePath
}
func test_can_read_file_as_text() {
let temporaryDirectory = self.createUniqueTemporaryDirectory()
let executable = self.createTestBinaryFile(temporaryDirectory)
XCTAssertEqual(
try! FileSystem.getStringFromFile(executable),
"""
!#/bin/bash
echo 'Hello world';
"""
)
}
func test_make_binary_executable() {
let temporaryDirectory = self.createUniqueTemporaryDirectory()
let executable = self.createTestBinaryFile(temporaryDirectory)
@ -57,6 +96,15 @@ class RealFileSystemTest: XCTestCase {
try! FileSystem.makeExecutable(executable)
XCTAssertTrue(FileSystem.isExecutableFile(executable))
XCTAssertFalse(FileSystem.isDirectory(executable))
XCTAssertFalse(FileSystem.isSymlink(executable))
}
func test_non_existent_file_is_not_symlink_or_directory() {
let path = "/path/that/does/not/exist"
XCTAssertFalse(FileSystem.isDirectory(path))
XCTAssertFalse(FileSystem.isSymlink(path))
}
func test_moving_file() {