New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
06-extract-ssh.t in vendors/t/fcm-make – NEMO

source: vendors/t/fcm-make/06-extract-ssh.t @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 4.3 KB
Line 
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#-------------------------------------------------------------------------------
24N_TESTS=6
25tests $N_TESTS
26#-------------------------------------------------------------------------------
27# Get a remote host for testing
28T_HOST=
29for 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
37done
38if [[ -z $T_HOST ]]; then
39    skip $N_TESTS 'fcm/t.cfg: "host" not defined'
40    exit 0
41fi
42#-------------------------------------------------------------------------------
43# Create a source tree on the remote host
44mkdir -p hello/{greet,hello,hi,.secret}
45for 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
50done
51T_HOST_WORK_DIR=$(ssh -oBatchMode=yes $T_HOST mktemp -d)
52rsync -a hello $T_HOST:$T_HOST_WORK_DIR
53rm -r hello
54#-------------------------------------------------------------------------------
55# Create a fcm-make.cfg
56cat >fcm-make.cfg <<__FCM_MAKE_CFG__
57steps=extract
58extract.ns=hello
59extract.location[hello]=$T_HOST:$T_HOST_WORK_DIR/hello
60__FCM_MAKE_CFG__
61#-------------------------------------------------------------------------------
62TEST_KEY="$TEST_KEY_BASE"
63run_pass "$TEST_KEY" fcm make
64grep -e '\[info\] location hello: 0' -e '\[info\] AU hello:0' fcm-make.log \
65    >"$TEST_KEY.log"
66file_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#-------------------------------------------------------------------------------
82TEST_KEY="$TEST_KEY_BASE-incr0"
83run_pass "$TEST_KEY" fcm make
84grep -e '\[info\]   dest:' -e '\[info\] source:' fcm-make.log \
85    >"$TEST_KEY.log"
86file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<__LOG__
87[info]   dest:   12 [U unchanged]
88[info] source:   12 [U from base]
89__LOG__
90#-------------------------------------------------------------------------------
91TEST_KEY="$TEST_KEY_BASE-incr1"
92echo 'Hello Martians' \
93    | ssh -oBatchMode=yes $T_HOST "cat >$T_HOST_WORK_DIR/hello/hello/hello_mars.txt"
94run_pass "$TEST_KEY" fcm make
95grep \
96    -e '\[info\]   dest:' \
97    -e '\[info\] source:' \
98    -e '\[info\] MU hello:0' \
99    fcm-make.log >"$TEST_KEY.log"
100file_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#-------------------------------------------------------------------------------
107ssh -oBatchMode=yes $T_HOST rm -r $T_HOST_WORK_DIR
108exit 0
Note: See TracBrowser for help on using the repository browser.