Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions test/dashboard.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down