LOGIN
Fullstack Ruby Developer
 · HanoiVietnam
Share
Report
Get Link
TUTORIAL

Checking json results diffs with automatic script

After upgrading from Rails 4 to Rails 5, we had to check differences of JSON results, just to make sure and to see the performance too. So I wrote a simple automatic script for that task.

#!/bin/bash
TIMEFORMAT=%3R
echo "Testing Rails 4 first..."
COUNTER=1
input="check-urls.txt"
while IFS= read -r var
do
  URL="http://z.api.coordisnap.com:3000$var"
  FILE_OUT="rails4_$COUNTER.output"
  echo -n "Rails 4 response time: "
  time wget -q "${URL}" --user-agent="Coordisnap/5.30.0(146) Android/5.0(21) Mobile" --header="Accept-Language: en-US" -O $FILE_OUT
  COUNTER=$(($COUNTER+1))
done < "$input"

echo -n "Rails 4 testing is finished. Are you ready to Rails 5 testing now?(y/n)"
read choice

if [ "$choice" == "y" ]; then
  echo "Testing Rails 5..."
  COUNTER=1
  while IFS= read -r var
  do
    URL="http://z.api.coordisnap.com:3000$var"
    FILE_OUT="rails5_$COUNTER.output"
    echo -n "Rails 5 response time: "
    time wget -q "${URL}" --user-agent="Coordisnap/5.30.0(146) Android/5.0(21) Mobile" --header="Accept-Language: en-US" -O $FILE_OUT
    COUNTER=$(($COUNTER+1))
  done < "$input"
else
  exit 1
fi


echo "Beautifying the jsons..."
COUNTER=1
while IFS= read -r var
do
  R_FILE_OUT="rails4_$COUNTER.output"
  R_JSON="rails4_$COUNTER.json"
  cat $R_FILE_OUT | jq . > $R_JSON
  rm $R_FILE_OUT
  P_FILE_OUT="rails5_$COUNTER.output"
  P_JSON="rails5_$COUNTER.json"
  cat $P_FILE_OUT | jq . > $P_JSON
  rm $P_FILE_OUT
  COUNTER=$(($COUNTER+1))
done < "$input"

echo "Comparing jsons..."
COUNTER=1
while IFS= read -r var
do
  R_JSON="rails4_$COUNTER.json"
  P_JSON="rails5_$COUNTER.json"
  DI_OT=$(diff $R_JSON $P_JSON)
        if [ "$DI_OT" == "" ]; then
    echo "$COUNTER - No differences"
  else
    echo "There're some differences between $R_JSON and $P_JSON"
        fi
  COUNTER=$(($COUNTER+1))
done < "$input"
0 like 
Like
Award Contribution
Leave a reply...
DISCOVER
CHAT
HIRE
ACTIVITY
FEED
Chat with us!
Help
Write something before you submit it!
Photo updated
Request Sent!
Updated
Copied to Clipboard