-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
12 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 |
---|---|---|
@@ -1,25 +1,52 @@ | ||
local folder_utils = require("devcontainer_cli.folder_utils") | ||
local folder_utils = require("devcontainer-cli.folder_utils") | ||
|
||
describe("In folder_utils functions", function() | ||
describe("folder_utils.get_root:", function() | ||
it( | ||
"checks if get_root function has the root folder as a reference even when we are in another folder", | ||
"check if first devcontainer directory when toplevel is false", | ||
function() | ||
-- dbg() | ||
-- This test assumes that we are in the root folder of the project | ||
local project_root_folder = vim.fn.getcwd() | ||
local project_root = vim.fn.getcwd() | ||
-- We change the current directory to a subfolder | ||
vim.fn.chdir("lua/devcontainer_cli") | ||
vim.fn.chdir("lua/devcontainer-cli") | ||
local devcontainer_cli_folder = vim.fn.getcwd() | ||
-- First we check that the we properly changed the directory | ||
assert(devcontainer_cli_folder == project_root_folder .. "/lua/devcontainer_cli") | ||
-- In such subfolder the function for getting the root_folder is called | ||
local root_folder = folder_utils.get_root() | ||
assert(devcontainer_cli_folder == project_root .. "/lua/devcontainer-cli") | ||
-- Verify that the project root is at the current level when toplevel is false | ||
local root_folder = folder_utils.get_root(false) | ||
-- From the subfolder, we check that the get_root function returns the folder where the git repo is located instead of the CWD | ||
print("ROOT" .. root_folder) | ||
print("PROJECT_ROOT" .. project_root_folder) | ||
assert(root_folder == project_root_folder) | ||
print("ROOT: " .. root_folder) | ||
print("PROJECT_ROOT: " .. project_root) | ||
assert(root_folder == project_root) | ||
-- After running the test we come back to the initial location | ||
vim.fn.chdir(project_root_folder) | ||
vim.fn.chdir(project_root) | ||
end | ||
) | ||
end) | ||
|
||
describe("In folder_utils.get_root:", function() | ||
it( | ||
"check if top most devcontainer directory when toplevel is true", | ||
function() | ||
-- dbg() | ||
-- This test assumes that we are in the root folder of the project | ||
local project_root = vim.fn.getcwd() | ||
-- We change the current directory to a subfolder | ||
vim.fn.chdir("lua/devcontainer-cli") | ||
local devcontainer_cli_folder = vim.fn.getcwd() | ||
-- First we check that the we properly changed the directory | ||
assert(devcontainer_cli_folder == project_root .. "/lua/devcontainer-cli") | ||
|
||
-- Verify that the project root is at HOME (location of top most devcontainer directory) when toplevel is true | ||
project_root = os.getenv("HOME") | ||
root_folder = folder_utils.get_root(true) | ||
|
||
-- From the subfolder, we check that the get_root function returns the folder where the git repo is located instead of the CWD | ||
print("ROOT: " .. root_folder) | ||
print("PROJECT_ROOT: " .. project_root) | ||
assert(root_folder == project_root) | ||
|
||
vim.fn.chdir(project_root) | ||
end | ||
) | ||
end) |