Skip to content

Commit cceaa34

Browse files
committed
Add yq command requirement check with tests
1 parent 6e2670e commit cceaa34

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

.cspell/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ esac
1919
exitcode
2020
fchastanet
2121
fplain
22+
François
2223
Inlines
2324
inlines
2425
installfile

.cspell/softwares.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ETAG
3333
fasd
3434
Fasd
3535
fchastanet
36+
François
3637
gdebi
3738
getent
3839
gettext

src/Linux/requireYqCommand.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2154
3+
# shellcheck disable=SC2034
4+
5+
# shellcheck source=src/batsHeaders.sh
6+
source "$(cd "${BATS_TEST_DIRNAME}/.." && pwd)/batsHeaders.sh"
7+
# shellcheck source=src/Linux/requireYqCommand.sh
8+
source "${srcDir}/Linux/requireYqCommand.sh"
9+
10+
function Linux::requireYqCommand::failure { #@test
11+
function Assert::commandExists() {
12+
return 1
13+
}
14+
15+
run Linux::requireYqCommand
16+
17+
assert_failure 1
18+
assert_output ""
19+
}
20+
21+
function Linux::requireYqCommand::success { #@test
22+
function Assert::commandExists() {
23+
return 0
24+
}
25+
26+
run Linux::requireYqCommand
27+
28+
assert_success
29+
assert_output ""
30+
}

src/Linux/requireYqCommand.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# @description ensure command yq is available
4+
# @exitcode 1 if yq command not available
5+
# @stderr diagnostics information is displayed
6+
Linux::requireYqCommand() {
7+
if [[ "${SKIP_REQUIRE_YQ:-0}" = "0" && "${SKIP_REQUIRES:-0}" = "0" ]]; then
8+
Assert::commandExists yq
9+
fi
10+
}

0 commit comments

Comments
 (0)