Skip to content

Commit 64eaef6

Browse files
committed
fix(ci): install jq on Alpine and skip JSON tests when jq is missing
1 parent fe2183e commit 64eaef6

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
run: |
8080
docker run --rm -v "$(pwd)":/project alpine:latest /bin/sh -c " \
8181
apk update && \
82-
apk add --no-cache bash make git && \
82+
apk add --no-cache bash make git jq && \
8383
adduser -D builder && \
8484
chown -R builder /project && \
8585
su - builder -c 'cd /project; make test';"

tests/unit/assert_json_test.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#!/usr/bin/env bash
22
# shellcheck disable=SC2329
33

4-
function set_up_before_script() {
5-
if ! command -v jq >/dev/null 2>&1; then
6-
bashunit::skip "jq is required for JSON assertions"
7-
return
8-
fi
9-
}
4+
_JQ_AVAILABLE=false
5+
if command -v jq >/dev/null 2>&1; then
6+
_JQ_AVAILABLE=true
7+
fi
108

119
function test_successful_assert_json_key_exists() {
10+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
1211
assert_empty "$(assert_json_key_exists ".name" '{"name":"bashunit","version":"1.0"}')"
1312
}
1413

1514
function test_successful_assert_json_key_exists_nested() {
15+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
1616
assert_empty "$(assert_json_key_exists ".data.id" '{"data":{"id":42}}')"
1717
}
1818

1919
function test_unsuccessful_assert_json_key_exists() {
20+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
2021
local json='{"name":"bashunit"}'
2122

2223
assert_same \
@@ -27,14 +28,17 @@ function test_unsuccessful_assert_json_key_exists() {
2728
}
2829

2930
function test_successful_assert_json_contains() {
31+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
3032
assert_empty "$(assert_json_contains ".name" "bashunit" '{"name":"bashunit","version":"1.0"}')"
3133
}
3234

3335
function test_successful_assert_json_contains_numeric() {
36+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
3437
assert_empty "$(assert_json_contains ".count" "42" '{"count":42}')"
3538
}
3639

3740
function test_unsuccessful_assert_json_contains_wrong_value() {
41+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
3842
local json='{"name":"bashunit"}'
3943

4044
assert_same \
@@ -45,6 +49,7 @@ function test_unsuccessful_assert_json_contains_wrong_value() {
4549
}
4650

4751
function test_unsuccessful_assert_json_contains_missing_key() {
52+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
4853
local json='{"name":"bashunit"}'
4954

5055
assert_same \
@@ -55,10 +60,12 @@ function test_unsuccessful_assert_json_contains_missing_key() {
5560
}
5661

5762
function test_successful_assert_json_equals() {
63+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
5864
assert_empty "$(assert_json_equals '{"b":2,"a":1}' '{"a":1,"b":2}')"
5965
}
6066

6167
function test_unsuccessful_assert_json_equals() {
68+
if [ "$_JQ_AVAILABLE" = false ]; then bashunit::skip "jq required"; return; fi
6269
local expected='{"a":1}'
6370
local actual='{"a":2}'
6471

0 commit comments

Comments
 (0)