-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test of spies failing to fix on main
- Loading branch information
Showing
6 changed files
with
71 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,49 @@ | ||
#!/bin/bash | ||
|
||
function test_mock_ps_when_executing_a_script() { | ||
skip "The mock is not been able to cat the output of the cat" | ||
return | ||
mock ps cat ./tests/functional/fixtures/doubles_ps_output | ||
|
||
assert_match_snapshot "$(./tests/functional/fixtures/doubles_script.sh)" | ||
} | ||
|
||
function test_mock_ps_when_executing_a_sourced_function() { | ||
skip "The mock is not been able to cat the output of the cat" | ||
return | ||
source ./tests/functional/fixtures/doubles_function.sh | ||
mock ps cat ./tests/functional/fixtures/doubles_ps_output | ||
|
||
assert_match_snapshot "$(top_mem)" | ||
} | ||
|
||
function test_spy_commands_called_once_when_executing_a_script() { | ||
skip "not working while executing commands outside a function" | ||
return | ||
|
||
spy ps | ||
spy awk | ||
spy head | ||
|
||
./tests/functional/fixtures/doubles_script.sh | ||
|
||
assert_have_been_called_times 1 ps | ||
assert_have_been_called_times 1 awk | ||
assert_have_been_called_times 1 head | ||
} | ||
|
||
function test_spy_commands_called_once_when_executing_a_sourced_function() { | ||
skip "The spies can not spy inside the scope of the function" | ||
return | ||
|
||
source ./tests/functional/fixtures/doubles_function.sh | ||
spy ps | ||
spy awk | ||
spy head | ||
|
||
top_mem | ||
|
||
assert_have_been_called_times 1 ps | ||
assert_have_been_called_times 1 awk | ||
assert_have_been_called_times 1 head | ||
} |
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,5 @@ | ||
#!/bin/bash | ||
|
||
function top_mem() { | ||
ps -eo cmd,%mem --sort=-%mem | awk '$2 >= 1.0 {print $0}' | head -n 3 | ||
} |
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,8 @@ | ||
CMD %MEM | ||
firefox 2.0 | ||
Xorg 1.6 | ||
jetbrains-toolbox 1.3 | ||
vitepress 1.0 | ||
bashunit 0.1 | ||
bash 0.0 | ||
ps 0.0 |
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,3 @@ | ||
#!/bin/bash | ||
|
||
ps -eo cmd,%mem --sort=-%mem | awk '$2 >= 1.0 {print $0}' | head -n 3 |
3 changes: 3 additions & 0 deletions
3
tests/functional/snapshots/doubles_test_sh_.test_mock_ps_when_executing_a_script.snapshot
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,3 @@ | ||
firefox 2.0 | ||
Xorg 1.6 | ||
jetbrains-toolbox 1.3 |
3 changes: 3 additions & 0 deletions
3
...tional/snapshots/doubles_test_sh_.test_mock_ps_when_executing_a_sourced_function.snapshot
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,3 @@ | ||
firefox 2.0 | ||
Xorg 1.6 | ||
jetbrains-toolbox 1.3 |