Skip to content

Commit

Permalink
trim
Browse files Browse the repository at this point in the history
  • Loading branch information
ericminio committed Apr 26, 2024
1 parent 0815cae commit 519c9e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stub-json/about/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source ../support/utils.sh

function test_json_header {
nginx_reload_configuration
type=$(curl --head http://localhost:8080/ping | grep "Content-Type:" | oneliner)
type=$(curl --head http://localhost:8080/ping | grep "Content-Type:" | trim)

assertequals "$type" "Content-Type: application/json"
}
Expand All @@ -17,3 +17,4 @@ function test_json_content {

assertequals "$body" '{ "alive":true, "value":42 }'
}

11 changes: 11 additions & 0 deletions support/utils.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

function trim {
sed "s/^[ $(printf '\n')$(printf '\r')]*//g" | sed "s/[ $(printf '\n')$(printf '\r')]*$//g"
}

function oneliner {
tr -d '\n' | tr -d '\r'
}
Expand All @@ -12,3 +16,10 @@ function json {
compact | sed 's/{/{ /g' | sed 's/}/ }/g' | sed 's/,/, /g'
}


function test_only_trim {
a=" $(printf '\r\n') 123 $(printf '\r\n') "
b=$(printf "%s" "$a" | trim)

assertequals "$b" "123"
}

0 comments on commit 519c9e7

Please sign in to comment.