@@ -46,6 +46,39 @@ extension Bytes {
46
46
47
47
class FileSystemTests : XCTestCase {
48
48
49
+ func testMoveFile_Succeeds_WhenMoveFileExecuted( ) throws {
50
+ let fs = FileSystem ( )
51
+ let directoryURL = fs. createTemporaryDirectoryURL ( )
52
+ try fs. createDirectory ( at: directoryURL)
53
+ let bytes = Bytes . megabytes ( 3 )
54
+ let data = bytes. generateRandomData ( )
55
+ let sourceFileUrl = try fs. createTemporaryFile ( data: data, baseURL: directoryURL)
56
+ XCTAssertTrue ( fs. fileExists ( atURL: sourceFileUrl) )
57
+ let destinationUrl = fs. documentsURL. appendingPathComponent ( " destination.tmp " )
58
+ try fs. moveFile ( from: sourceFileUrl, to: destinationUrl)
59
+ XCTAssertTrue ( fs. fileExists ( atURL: destinationUrl) )
60
+ fs. removeDirectoryIfExists ( directoryURL: sourceFileUrl)
61
+ fs. removeDirectoryIfExists ( directoryURL: destinationUrl)
62
+ }
63
+
64
+ func testMoveFile_Succeeds_WhenFileAlreadyExists( ) throws {
65
+ let fs = FileSystem ( )
66
+ let directoryURL = fs. createTemporaryDirectoryURL ( )
67
+ try fs. createDirectory ( at: directoryURL)
68
+ let bytes = Bytes . megabytes ( 3 )
69
+ let data = bytes. generateRandomData ( )
70
+ var sourceFileUrl = try fs. createTemporaryFile ( data: data, baseURL: directoryURL)
71
+ XCTAssertTrue ( fs. fileExists ( atURL: sourceFileUrl) )
72
+ let destinationUrl = fs. documentsURL. appendingPathComponent ( " destination.tmp " )
73
+ try fs. moveFile ( from: sourceFileUrl, to: destinationUrl)
74
+ XCTAssertTrue ( fs. fileExists ( atURL: destinationUrl) )
75
+ sourceFileUrl = try fs. createTemporaryFile ( data: data, baseURL: directoryURL)
76
+ try fs. moveFile ( from: sourceFileUrl, to: destinationUrl)
77
+ XCTAssertTrue ( fs. fileExists ( atURL: destinationUrl) )
78
+ fs. removeDirectoryIfExists ( directoryURL: sourceFileUrl)
79
+ fs. removeDirectoryIfExists ( directoryURL: destinationUrl)
80
+ }
81
+
49
82
func testFileExists( ) throws {
50
83
let fs = FileSystem ( )
51
84
let directoryURL = fs. createTemporaryDirectoryURL ( )
0 commit comments