Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erichlf committed Apr 28, 2024
1 parent 97d72b8 commit 6711505
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test:
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedFile tests/devcontainer_cli/folder_utils_spec.lua"
-c "PlenaryBustedFile tests/devcontainer_cli/unit_tests.lua"

test_all:
@nvim \
Expand Down
26 changes: 17 additions & 9 deletions lua/devcontainer-cli/devcontainer_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,38 @@ end

--- execute command
---@param cmd (string) the command to execute in the devcontainer terminal
local function exec_command(cmd)
function M.exec_command(cmd)
vim.fn.termopen(
cmd,
{
on_exit = on_exit,
on_stdout = function(_, _, _)
vim.api.nvim_win_call(
win,
function()
vim.cmd("normal! G")
end
)
if win ~= -1 then
vim.api.nvim_win_call(
win,
function()
vim.cmd("normal! G")
end
)
else
vim.notify("Executed " .. cmd)
end
end,
}
)
vim.api.nvim_set_current_buf(buffer)
if buffer ~= -1 then
vim.api.nvim_set_current_buf(buffer)
else
vim.notify("No buffer created, therefore no output from command will be visible", vim.log.levels.WARN)
end
end

-- create a new window and execute the given command
---@param cmd (string) the command to execute in the devcontainer terminal
local function spawn_and_execute(cmd)
prev_win = vim.api.nvim_get_current_win()
win, buffer = windows_utils.open_floating_window(on_detach)
exec_command(cmd)
M.exec_command(cmd)
end

-- build the initial part of a devcontainer command
Expand Down
2 changes: 1 addition & 1 deletion lua/devcontainer-cli/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
-- TODO: create a check for DevcontainerExec

function M.check()
-- start("devcontainer-cli")
start("devcontainer-cli")
local required_binaries = {
"docker",
"devcontainer",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local folder_utils = require("devcontainer-cli.folder_utils")
local utils = require("devcontainer-cli.devcontainer_utils")

describe("folder_utils.get_root:", function()
it(
Expand Down Expand Up @@ -39,7 +40,7 @@ describe("folder_utils.get_root:", function()

-- 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)
local 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)
Expand All @@ -50,3 +51,12 @@ describe("folder_utils.get_root:", function()
end
)
end)

describe("devcontainer_utils.exec_command:", function()
it(
"check if a command can be executed",
function()
utils.exec_command("echo 'Hello World!'")
end
)
end)

0 comments on commit 6711505

Please sign in to comment.