diff --git a/dashboard.sh b/dashboard.sh index bcf8677..10a9e1e 100755 --- a/dashboard.sh +++ b/dashboard.sh @@ -260,6 +260,8 @@ else if ($5 == "null") { printf "{\"date\":\"%s\",\"module\":\"%s\",\"channels\":\"%s\",\"namespace\":\"%s\",\"value\":null}", $1, $2, $3, $4 + } else if ($5 ~ /^[0-9]+$/) { + printf "{\"date\":\"%s\",\"module\":\"%s\",\"channels\":\"%s\",\"namespace\":\"%s\",\"value\":%s}", $1, $2, $3, $4, $5 } else { printf "{\"date\":\"%s\",\"module\":\"%s\",\"channels\":\"%s\",\"namespace\":\"%s\",\"value\":\"%s\"}", $1, $2, $3, $4, $5 } diff --git a/test/dashboard.bats b/test/dashboard.bats index eb7871b..eadd9f7 100644 --- a/test/dashboard.bats +++ b/test/dashboard.bats @@ -51,6 +51,18 @@ teardown() { echo "$output" | jq -e '.[0] | has("date") and has("module") and has("value")' > /dev/null } +@test "bugfix: json output should have correct numeric types" { + run ./dashboard.sh -f json + [ "$status" -eq 0 ] + # Check that a known numeric value is a number, not a string + github_stars_value=$(echo "$output" | jq '.[] | select(.module == "github" and .channels == "stars" and .namespace == "repo.attogram.base") | .value') + [ "$(jq 'type' <<< "$github_stars_value")" = '"number"' ] + + # Check that a known numeric value from another module is also a number + hackernews_karma_value=$(echo "$output" | jq '.[] | select(.module == "hackernews") | .value') + [ "$(jq 'type' <<< "$hackernews_karma_value")" = '"number"' ] +} + @test "integration: xml output should contain root element and metric data" { run ./dashboard.sh -f xml [ "$status" -eq 0 ]