summaryrefslogtreecommitdiff
path: root/tests/trove-id.script
blob: ee382de142929e80f30dac97f83d2b2ce78eae40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
#
# Copyright (C) 2012-2013,2015  Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.


## Verify that trove-id (and by corollary trove-host) work properly.

set -eu

RAWDUMP="$DATADIR/raw-configdump"
PROCESSEDDUMP="$DATADIR/processed-configdump"

# Step 1, gather all the raw and processed repo-alias entries

"$SRCDIR/scripts/test-morph" \
    --trove-host="TROVEHOST" \
    --trove-id="fudge" \
    --trove-id="github" \
    --dump-config > "$RAWDUMP"
env MORPH_DUMP_PROCESSED_CONFIG=1 "$SRCDIR/scripts/test-morph" \
    --trove-host="TROVEHOST" \
    --trove-id="fudge" \
    --trove-id="github" \
    > "$PROCESSEDDUMP"

RAW_ALIAS=$(grep repo-alias "$RAWDUMP" | cut -d\  -f3-)
PROCESSED_ALIAS=$(grep repo-alias "$PROCESSEDDUMP" | cut -d\  -f3-)

find_alias () {
    ALIASES="$1"
    WHICH="$2"
    for alias in $ALIASES; do
        alias=$(echo $alias | sed -e's/,$//')
        prefix=$(echo $alias | cut -d= -f1)
        if test "x$WHICH" = "x$prefix"; then
            echo $alias
            exit 0
        fi
    done
}

# Step 2, all raw aliases should be in processed aliases unchanged.  As part of
# this, we're also validating that the 'github' prefix we pass in does not
# affect the alias output since it is overridden by repo-alias.

for raw_alias in $RAW_ALIAS; do
    raw_alias=$(echo $raw_alias | sed -e's/,$//')
    raw_prefix=$(echo $raw_alias | cut -d= -f1)
    processed_alias=$(find_alias "$PROCESSED_ALIAS" "$raw_prefix")
    if test "x$raw_alias" != "x$processed_alias"; then
        echo >&2 "Raw $raw_alias not in processed aliases"
    fi
done

# Step 3, all aliases in the processed aliases which do not come from the raw
# aliases should contain the trove host.

for processed_alias in $PROCESSED_ALIAS; do
    processed_alias=$(echo $processed_alias | sed -e's/,$//')
    processed_prefix=$(echo $processed_alias | cut -d= -f1)
    raw_alias=$(find_alias "$RAW_ALIAS" "$processed_prefix")
    if test "x$raw_alias" = "x"; then
        grep_out=$(echo "$processed_alias" | grep TROVEHOST)
        if test "x$grep_out" = "x"; then
            echo >&2 "Processed $processed_alias does not mention TROVEHOST"
        fi
    fi
done

# Step 4, validate that the processed aliases do contain a baserock and an
# upstream alias since those are implicit in morph's behaviour.

for prefix in baserock upstream; do
    processed_alias=$(find_alias "$PROCESSED_ALIAS" "$prefix")
    if test "x$processed_alias" = "x"; then
        echo >&2 "Processed aliases lack $prefix prefix"
    fi
done

# Step 5, validate that the fudge prefix has been correctly expanded as though
# it were fudge=fudge#ssh#ssh

fudge_alias=$(find_alias "$PROCESSED_ALIAS" "fudge")
desired_fudge="fudge=ssh://git@TROVEHOST/fudge/%s#ssh://git@TROVEHOST/fudge/%s"
if test "x$fudge_alias" != "x$desired_fudge"; then
    echo >&2 "Fudge alias was '$fudge_alias' where we wanted '$desired_fudge'"
fi