1#!/usr/bin/env bash 2 3set -x 4 5if [ $# -ne 2 ]; then 6 echo "This script need exactly two arguments" 7 exit 1 8fi 9 10rootdir=$(readlink -f $(dirname $0)/../..) 11 12# Compare two JSON files. 13# 14# NOTE: Order of objects in JSON can change by just doing loads -> dumps so all JSON objects (not arrays) are sorted by 15# config_filter.py script. Sorted output is used to compare JSON output. 16# 17 18tmp_file_1=$(mktemp /tmp/$(basename ${1}).XXX) 19tmp_file_2=$(mktemp /tmp/$(basename ${2}).XXX) 20ret=0 21 22$rootdir/test/json_config/config_filter.py -method "sort" < $1 > $tmp_file_1 23$rootdir/test/json_config/config_filter.py -method "sort" < $2 > $tmp_file_2 24 25if ! diff -u $tmp_file_1 $tmp_file_2; then 26 ret=1 27 28 echo "=== Start of file: $tmp_file_1 ===" 29 cat $tmp_file_1 30 echo "=== End of file: $tmp_file_1 ===" 31 echo "" 32 echo "=== Start of file: $tmp_file_2 ===" 33 cat $tmp_file_2 34 echo "=== End of file: $tmp_file_2 ===" 35 echo "" 36else 37 echo "INFO: JSON config files are the same" 38fi 39 40rm $tmp_file_1 $tmp_file_2 41exit $ret 42