mirror of
https://github.com/CompeyDev/lune-packaging.git
synced 2025-01-09 12:19:09 +00:00
Implement tests for new fs move api
This commit is contained in:
parent
1fdc6d088c
commit
a59753569f
3 changed files with 62 additions and 3 deletions
|
@ -138,15 +138,15 @@ declare fs: {
|
|||
|
||||
An error will be thrown in the following situations:
|
||||
|
||||
* The current process lacks permissions to read at `from` or `to`.
|
||||
* The current process lacks permissions to read at `from` or write at `to`.
|
||||
* The new path exists on a different mount point.
|
||||
* Some other I/O error occurred.
|
||||
|
||||
@param from The path to move from
|
||||
@param to The path to move to
|
||||
@param overwriteOrOptions Options the target path, such as if should be overwritten if it already exists
|
||||
@param overwriteOrOptions Options for the target path, such as if should be overwritten if it already exists
|
||||
]=]
|
||||
move: (from: string, to: string, overwriteOrOptions: boolean | FsWriteOptions) -> (),
|
||||
move: (from: string, to: string, overwriteOrOptions: (boolean | FsWriteOptions)?) -> (),
|
||||
}
|
||||
|
||||
type NetMethod = "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "PATCH"
|
||||
|
|
|
@ -43,6 +43,7 @@ macro_rules! create_tests {
|
|||
create_tests! {
|
||||
fs_files: "fs/files",
|
||||
fs_dirs: "fs/dirs",
|
||||
fs_move: "fs/move",
|
||||
net_request_codes: "net/request/codes",
|
||||
net_request_methods: "net/request/methods",
|
||||
net_request_redirect: "net/request/redirect",
|
||||
|
|
58
tests/fs/move.luau
Normal file
58
tests/fs/move.luau
Normal file
|
@ -0,0 +1,58 @@
|
|||
-- Generate test data & make sure our bin dir exists
|
||||
|
||||
local binary = ""
|
||||
for _ = 1, 1024 do
|
||||
binary ..= string.char(math.random(1, 127))
|
||||
end
|
||||
|
||||
local json = net.jsonEncode({
|
||||
Foo = "Bar",
|
||||
Hello = "World",
|
||||
Inner = { Array = { 1, 2, 3 } },
|
||||
}, true)
|
||||
|
||||
fs.writeDir("bin")
|
||||
|
||||
-- Write both of our files
|
||||
|
||||
fs.writeFile("bin/move_test_binary", binary)
|
||||
fs.writeFile("bin/move_test_json.json", json)
|
||||
|
||||
-- Move / rename them to something else, to test we
|
||||
-- change the prefix in the names from "move" to "moved"
|
||||
|
||||
fs.move("bin/move_test_binary", "bin/moved_test_binary")
|
||||
fs.move("bin/move_test_json.json", "bin/moved_test_json.json")
|
||||
|
||||
-- Make sure reading the files we just
|
||||
-- wrote gets us back the original strings
|
||||
|
||||
assert(
|
||||
fs.readFile("bin/moved_test_binary") == binary,
|
||||
"Binary file round-trip resulted in different strings"
|
||||
)
|
||||
|
||||
assert(
|
||||
fs.readFile("bin/moved_test_json.json") == json,
|
||||
"JSON file round-trip resulted in different strings"
|
||||
)
|
||||
|
||||
-- Remove the files and make sure
|
||||
-- the APIs say they no longer exist
|
||||
|
||||
fs.removeFile("bin/moved_test_binary")
|
||||
fs.removeFile("bin/moved_test_json.json")
|
||||
|
||||
assert(not fs.isDir("bin/moved_test_binary"), "Binary after removal isDir check failed")
|
||||
assert(not fs.isFile("bin/moved_test_binary"), "Binary after removal isFile check failed")
|
||||
|
||||
assert(not fs.isDir("bin/moved_test_json.json"), "JSON after removal isDir check failed")
|
||||
assert(not fs.isFile("bin/moved_test_json.json"), "JSON after removal isFile check failed")
|
||||
|
||||
-- Also make sure files and dirs at the paths before moving do not exist
|
||||
|
||||
assert(not fs.isDir("bin/moved_test_binary"), "Binary file path still existed after moving")
|
||||
assert(not fs.isFile("bin/moved_test_binary"), "Binary file path still existed after moving")
|
||||
|
||||
assert(not fs.isDir("bin/moved_test_json.json"), "JSON file path still existed after moving")
|
||||
assert(not fs.isFile("bin/moved_test_json.json"), "JSON file path still existed after moving")
|
Loading…
Reference in a new issue