// // FilePermissionTests.swift // FileOtterTests // // Created by Sami Samhuri on 2025-08-19. // @testable import FileOtter import XCTest final class FilePermissionTests: XCTestCase { var tempDir: URL! var testFile: URL! var readOnlyFile: URL! var executableFile: URL! override func setUpWithError() throws { tempDir = URL.temporaryDirectory .appendingPathComponent("FilePermissionTests-\(UUID().uuidString)") try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true) testFile = tempDir.appendingPathComponent("test.txt") try "Test content".write(to: testFile, atomically: true, encoding: .utf8) readOnlyFile = tempDir.appendingPathComponent("readonly.txt") try "Read only".write(to: readOnlyFile, atomically: true, encoding: .utf8) executableFile = tempDir.appendingPathComponent("script.sh") try "#!/bin/sh\necho hello".write(to: executableFile, atomically: true, encoding: .utf8) } override func tearDownWithError() throws { if FileManager.default.fileExists(atPath: tempDir.path) { try FileManager.default.removeItem(at: tempDir) } } // MARK: - Basic Permission Tests func testIsReadable() throws { // TODO: Implement // File.isReadable(url) returns true for readable files } func testIsWritable() throws { // TODO: Implement // File.isWritable(url) returns true for writable files } func testIsExecutable() throws { // TODO: Implement // File.isExecutable(url) returns true for executable files } func testIsExecutableForNonExecutable() throws { // TODO: Implement // File.isExecutable(url) returns false for non-executable } // MARK: - Ownership Tests func testIsOwned() throws { // TODO: Implement // File.isOwned(url) returns true for files owned by effective user } func testIsGroupOwned() throws { // TODO: Implement // File.isGroupOwned(url) returns true for files owned by effective group } // MARK: - World Permission Tests func testIsWorldReadable() throws { // TODO: Implement // File.isWorldReadable(url) returns permission bits if world readable } func testIsWorldReadableForPrivate() throws { // TODO: Implement // File.isWorldReadable(url) returns nil if not world readable } func testIsWorldWritable() throws { // TODO: Implement // File.isWorldWritable(url) returns permission bits if world writable } func testIsWorldWritableForProtected() throws { // TODO: Implement // File.isWorldWritable(url) returns nil if not world writable } // MARK: - Special Bit Tests func testIsSetuid() throws { // TODO: Implement // File.isSetuid(url) returns true if setuid bit is set } func testIsSetgid() throws { // TODO: Implement // File.isSetgid(url) returns true if setgid bit is set } func testIsSticky() throws { // TODO: Implement // File.isSticky(url) returns true if sticky bit is set } // MARK: - chmod Tests func testChmod() throws { // TODO: Implement // File.chmod(url, permissions) changes file permissions } func testChmodThrowsForNonExistent() throws { // TODO: Implement } func testLchmod() throws { // TODO: Implement // File.lchmod(url, permissions) changes symlink permissions } func testInstanceChmod() throws { // TODO: Implement // file.chmod(permissions) changes open file permissions } // MARK: - chown Tests func testChown() throws { // TODO: Implement // File.chown(url, owner, group) changes ownership // Note: May require special privileges } func testChownWithNilValues() throws { // TODO: Implement // nil owner or group means don't change that value } func testLchown() throws { // TODO: Implement // File.lchown(url, owner, group) changes symlink ownership } func testInstanceChown() throws { // TODO: Implement // file.chown(owner, group) changes open file ownership } // MARK: - umask Tests func testUmask() throws { // TODO: Implement // File.umask() returns current umask } func testUmaskSet() throws { // TODO: Implement // File.umask(mask) sets umask and returns previous value } }