-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: cover _pure_prompt_k8s and add mocks helpers
- Loading branch information
1 parent
4abd9a7
commit 020a1a7
Showing
4 changed files
with
90 additions
and
1 deletion.
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
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,38 @@ | ||
source (dirname (status filename))/fixtures/constants.fish | ||
source (dirname (status filename))/mocks/mocks.fish | ||
source (dirname (status filename))/../functions/_pure_prompt_k8s.fish | ||
source (dirname (status filename))/../functions/_pure_k8s_context.fish | ||
source (dirname (status filename))/../functions/_pure_k8s_namespace.fish | ||
source (dirname (status filename))/../functions/_pure_check_availability.fish | ||
@echo (_print_filename (status filename)) | ||
|
||
function before_each | ||
_purge_configs | ||
_disable_colors | ||
end | ||
|
||
function teardown | ||
_clean_all_mocks | ||
end | ||
|
||
|
||
@test "_pure_prompt_k8s: ensure default behaviour has no error" ( | ||
_pure_prompt_k8s | ||
) $status -eq $SUCCESS | ||
|
||
|
||
@test "_pure_prompt_k8s: ensure default behaviour print nothing" ( | ||
echo (_pure_prompt_k8s) | ||
) = $EMPTY | ||
|
||
|
||
before_each | ||
@test "_pure_prompt_k8s: print kubernetes context and namespace" ( | ||
set --universal pure_enable_k8s true | ||
set --universal pure_symbol_k8s_prefix "☸" | ||
_mock kubectl | ||
|
||
_pure_prompt_k8s | ||
) = '☸ my-context/my-namespace' | ||
|
||
teardown |
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,17 @@ | ||
function kubectl \ | ||
--description 'kubectl mock for test' \ | ||
--argument-names \ | ||
topcommand \ | ||
subcommand | ||
|
||
if test $topcommand = config | ||
if test $subcommand = current-context | ||
echo my-context | ||
end | ||
if test $subcommand = view | ||
echo my-namespace | ||
end | ||
else | ||
echo "unknown command" | ||
end | ||
end # mock |
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,31 @@ | ||
function _mock \ | ||
--description "Invoke a mock function" \ | ||
--argument-names \ | ||
function_name | ||
|
||
set mock_filepath (dirname (status filename))/$function_name.mock.fish | ||
if test -e $mock_filepath | ||
source (dirname (status filename))/$function_name.mock.fish | ||
set --global --append __mocks $function_name | ||
end | ||
end | ||
|
||
|
||
function _clean_mock \ | ||
--description "Clean a mock function" \ | ||
--argument-names \ | ||
function_name | ||
|
||
functions --erase $function_name | ||
end | ||
|
||
function _clean_all_mocks \ | ||
--description "Clean all mock function" | ||
set --local new_mocks | ||
for mock in $__mocks | ||
if functions --query $mock | ||
functions --erase $mock | ||
end | ||
end | ||
set --global __mocks | ||
end |