File: test-save-empty.sh

package info (click to toggle)
augeas 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,216 kB
  • ctags: 5,097
  • sloc: ansic: 48,281; sh: 11,387; cpp: 624; yacc: 515; ruby: 444; makefile: 319; lex: 198; perl: 27; pascal: 27
file content (55 lines) | stat: -rwxr-xr-x 1,133 bytes parent folder | download | duplicates (3)
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
#! /bin/bash

# Test that we report an error when writing to nonexistant dirs
# but that we do create new files correctly

save_hosts() {
opts="--nostdinc -r $ROOT -I $abs_top_srcdir/lenses"
(augtool $opts | grep ^/augeas) <<EOF
set /files/etc/hosts/1/ipaddr 127.0.0.1
set /files/etc/hosts/1/canonical localhost
save
print /augeas/files/etc/hosts/error
EOF
}

expected_errors() {
cat <<EOF
/augeas/files/etc/hosts/error = "open_augnew"
/augeas/files/etc/hosts/error/message = "No such file or directory"
EOF
}

ROOT=$abs_top_builddir/build/test-save-empty
HOSTS=$ROOT/etc/hosts

rm -rf $ROOT
mkdir -p $ROOT
ACTUAL=$(save_hosts)
EXPECTED=$(expected_errors)

if [ "$ACTUAL" != "$EXPECTED" ]
then
    echo "No error on missing /etc directory"
    exit 1
fi

mkdir -p $ROOT/etc
ACTUAL=$(save_hosts)
if [ -n "$ACTUAL" ] ; then
    echo "Error creating file:"
    echo $ACTUAL
    exit 1
fi

if [ ! -f $HOSTS ] ; then
    echo "File ${HOSTS} was not created"
    exit 1
fi

printf '127.0.0.1\tlocalhost\n' > $HOSTS.expected

if ! cmp $HOSTS $HOSTS.expected > /dev/null 2>&1 ; then
    echo "Contents of $HOSTS are incorrect"
    exit 1
fi