-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilities: - list_directories
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
local File = require "coredor.file" | ||
|
||
local M = {} | ||
|
||
function M.list_directories(path_string) | ||
if path_string == nil then | ||
error "path must not be nil" | ||
end | ||
|
||
local file = File:new(path_string) | ||
local plenary_file = file:as_plenary() | ||
|
||
if not plenary_file:exists() then | ||
error("path '" .. path_string .. "' must exist") | ||
end | ||
if not plenary_file:is_dir() then | ||
error( | ||
"path '" .. path_string .. "' must point to directory, not a file" | ||
) | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
local spec = require "coredor.spec" | ||
local coredor = require "coredor" | ||
|
||
describe("list directories", function() | ||
local utils = require "obs.utils" | ||
local list_directories = utils.list_directories | ||
local temp_file_fixture = spec.temp_file_fixture() | ||
|
||
it("nil parameter causes error", function() | ||
assert.has_error(function() | ||
list_directories() | ||
end, "path must not be nil") | ||
end) | ||
|
||
it("not existing directory causes error", function() | ||
local invalid_directory_path = "invalid directory " .. coredor.uuid() | ||
|
||
assert.has_error(function() | ||
list_directories(invalid_directory_path) | ||
end, "path '" .. invalid_directory_path .. "' must exist") | ||
end) | ||
|
||
it("not directory causes error", function() | ||
local file_path = temp_file_fixture.path | ||
|
||
assert.has_error(function() | ||
list_directories(file_path) | ||
end, "path '" .. file_path .. "' must point to directory, not a file") | ||
end) | ||
end) |