1 | #!/bin/bash |
---|
2 | #------------------------------------------------------------------------------- |
---|
3 | # (C) British Crown Copyright 2006-17 Met Office. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | #------------------------------------------------------------------------------- |
---|
20 | # Tests for "fcm make", "extract" from SSH location. |
---|
21 | #------------------------------------------------------------------------------- |
---|
22 | . $(dirname $0)/test_header |
---|
23 | #------------------------------------------------------------------------------- |
---|
24 | N_TESTS=6 |
---|
25 | tests $N_TESTS |
---|
26 | #------------------------------------------------------------------------------- |
---|
27 | # Get a remote host for testing |
---|
28 | T_HOST= |
---|
29 | for FILE in $HOME/.metomi/fcm/t.cfg $FCM_HOME/etc/fcm/t.cfg; do |
---|
30 | if [[ ! -f $FILE || ! -r $FILE ]]; then |
---|
31 | continue |
---|
32 | fi |
---|
33 | T_HOST=$(fcm cfg $FILE | sed '/^ *host *=/!d; s/^ *host *= *//' | tail -1) |
---|
34 | if [[ -n $T_HOST ]]; then |
---|
35 | break |
---|
36 | fi |
---|
37 | done |
---|
38 | if [[ -z $T_HOST ]]; then |
---|
39 | skip $N_TESTS 'fcm/t.cfg: "host" not defined' |
---|
40 | exit 0 |
---|
41 | fi |
---|
42 | #------------------------------------------------------------------------------- |
---|
43 | # Create a source tree on the remote host |
---|
44 | mkdir -p hello/{greet,hello,hi,.secret} |
---|
45 | for NAME in mercury venus earth mars; do |
---|
46 | echo "Greet $NAME" >hello/greet/greet_${NAME}.txt |
---|
47 | echo "Hello $NAME" >hello/hello/hello_${NAME}.txt |
---|
48 | echo "[Alien-speak] $NAME" >hello/.secret/hello_${NAME}.txt |
---|
49 | echo "Hi $NAME" >hello/hi/hi_${NAME}.txt |
---|
50 | done |
---|
51 | T_HOST_WORK_DIR=$(ssh -oBatchMode=yes $T_HOST mktemp -d) |
---|
52 | rsync -a hello $T_HOST:$T_HOST_WORK_DIR |
---|
53 | rm -r hello |
---|
54 | #------------------------------------------------------------------------------- |
---|
55 | # Create a fcm-make.cfg |
---|
56 | cat >fcm-make.cfg <<__FCM_MAKE_CFG__ |
---|
57 | steps=extract |
---|
58 | extract.ns=hello |
---|
59 | extract.location[hello]=$T_HOST:$T_HOST_WORK_DIR/hello |
---|
60 | __FCM_MAKE_CFG__ |
---|
61 | #------------------------------------------------------------------------------- |
---|
62 | TEST_KEY="$TEST_KEY_BASE" |
---|
63 | run_pass "$TEST_KEY" fcm make |
---|
64 | grep -e '\[info\] location hello: 0' -e '\[info\] AU hello:0' fcm-make.log \ |
---|
65 | >"$TEST_KEY.log" |
---|
66 | file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<__LOG__ |
---|
67 | [info] location hello: 0: $T_HOST:$T_HOST_WORK_DIR/hello |
---|
68 | [info] AU hello:0 hi/hi_mars.txt |
---|
69 | [info] AU hello:0 greet/greet_venus.txt |
---|
70 | [info] AU hello:0 hello/hello_mercury.txt |
---|
71 | [info] AU hello:0 hello/hello_venus.txt |
---|
72 | [info] AU hello:0 greet/greet_mars.txt |
---|
73 | [info] AU hello:0 hi/hi_mercury.txt |
---|
74 | [info] AU hello:0 greet/greet_earth.txt |
---|
75 | [info] AU hello:0 greet/greet_mercury.txt |
---|
76 | [info] AU hello:0 hi/hi_earth.txt |
---|
77 | [info] AU hello:0 hello/hello_earth.txt |
---|
78 | [info] AU hello:0 hello/hello_mars.txt |
---|
79 | [info] AU hello:0 hi/hi_venus.txt |
---|
80 | __LOG__ |
---|
81 | #------------------------------------------------------------------------------- |
---|
82 | TEST_KEY="$TEST_KEY_BASE-incr0" |
---|
83 | run_pass "$TEST_KEY" fcm make |
---|
84 | grep -e '\[info\] dest:' -e '\[info\] source:' fcm-make.log \ |
---|
85 | >"$TEST_KEY.log" |
---|
86 | file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<__LOG__ |
---|
87 | [info] dest: 12 [U unchanged] |
---|
88 | [info] source: 12 [U from base] |
---|
89 | __LOG__ |
---|
90 | #------------------------------------------------------------------------------- |
---|
91 | TEST_KEY="$TEST_KEY_BASE-incr1" |
---|
92 | echo 'Hello Martians' \ |
---|
93 | | ssh -oBatchMode=yes $T_HOST "cat >$T_HOST_WORK_DIR/hello/hello/hello_mars.txt" |
---|
94 | run_pass "$TEST_KEY" fcm make |
---|
95 | grep \ |
---|
96 | -e '\[info\] dest:' \ |
---|
97 | -e '\[info\] source:' \ |
---|
98 | -e '\[info\] MU hello:0' \ |
---|
99 | fcm-make.log >"$TEST_KEY.log" |
---|
100 | file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<__LOG__ |
---|
101 | [info] MU hello:0 hello/hello_mars.txt |
---|
102 | [info] dest: 1 [M modified] |
---|
103 | [info] dest: 11 [U unchanged] |
---|
104 | [info] source: 12 [U from base] |
---|
105 | __LOG__ |
---|
106 | #------------------------------------------------------------------------------- |
---|
107 | ssh -oBatchMode=yes $T_HOST rm -r $T_HOST_WORK_DIR |
---|
108 | exit 0 |
---|