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

👌 FileSystem changes, rework and testing

This commit is contained in:
2022-11-01 13:47:16 +01:00
parent e8c85f93f9
commit 8417d637fe
26 changed files with 299 additions and 82 deletions

View File

@ -0,0 +1,61 @@
//
// TestableFileSystemTest.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 01/11/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import XCTest
class TestableFileSystemTest: XCTestCase {
override class func setUp() {
ActiveFileSystem.useTestable([
"/home/user/bin": .fake(.directory),
"/home/user/bin/foo": .fake(.binary),
"/home/user/documents": .fake(.directory),
"/home/user/docs": .fake(.symlink, "/home/user/documents"),
"/home/user/documents/nice.txt": .fake(.text, "69"),
"/home/user/documents/script.sh": .fake(.text, "echo 'cool';")
])
}
func test_testable_fs_is_in_use() {
XCTAssertTrue(FileSystem is TestableFileSystem)
}
func test_binary_directory_exists() {
XCTAssertTrue(FileSystem.directoryExists("/home/user/bin"))
}
func test_binary_directory_is_writable() {
XCTAssertTrue(FileSystem.isWriteableFile("/home/user/bin"))
}
func test_binary_exists() {
XCTAssertTrue(FileSystem.isExecutableFile("/home/user/bin/foo"))
}
func test_can_write_text_to_executable() throws {
try! FileSystem.writeAtomicallyToFile("/home/user/bin/bar", content: "bar bar bar!")
XCTAssertFalse(FileSystem.isExecutableFile("/home/user/bin/bar"))
try! FileSystem.makeExecutable("/home/user/bin/bar")
XCTAssertTrue(FileSystem.isExecutableFile("/home/user/bin/bar"))
}
func test_can_create_directory() throws {
try! FileSystem.createDirectory(
"/home/nico/phpmon/config",
withIntermediateDirectories: true
)
XCTAssertTrue(FileSystem.anyExists("/home/nico/phpmon/config"))
XCTAssertTrue(FileSystem.directoryExists("/home/nico/phpmon/config"))
}
// TODO: Implement and test the remove() and move() methods and reorganize method order
}

View File

@ -1,6 +1,6 @@
//
// SystemShellTest.swift
// phpmon-tests
// PHP Monitor
//
// Created by Nico Verbruggen on 28/09/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// ShellTest.swift
// phpmon-tests
// TestableShellTest.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 20/09/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
@ -8,7 +8,7 @@
import XCTest
class FakeShellTest: XCTestCase {
class TestableShellTest: XCTestCase {
func test_fake_shell_output_can_be_declared() async {
let greeting = BatchFakeShellOutput(items: [
.instant("Hello world\n"),