Refactor tests into jjb-tests directory
[releng/global-jjb.git] / jjb-compare-xml.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # This script tests jjb templates by comparing the result with expected output.
13
14 test_dir=$(mktemp -d)
15 script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
16 expected_xml_dir="$script_dir/jjb-test/expected-xml"
17
18 echo "Script Directory: $script_dir"
19 echo "Test Directory: $test_dir"
20
21 jenkins-jobs test --recursive -o "$test_dir" "$script_dir"
22
23 fail=false
24 for xml in "$test_dir"/*; do
25     job=$(basename "$xml")
26     if ! cmp "$expected_xml_dir/$job" "$xml"; then
27         echo "Differences detected in $job"
28         diff "$expected_xml_dir/$job" "$xml"
29         fail=true
30     fi
31 done
32
33 # Cleanup
34 rm -rf "$test_dir"
35
36 if $fail; then
37     echo "Differences detected. Check above for jobs that have been changed."
38     exit 1
39 fi