blob: 1f15be13d26a9e9b1977d3039ce54ac31c67cf77 [file] [log] [blame]
#!/bin/sh
# Test the mounttabled binary
#
# This test starts a mounttable server with the neighborhood option enabled,
# and mounts 1) the mounttable on itself as 'myself', and 2) www.google.com:80
# as 'google'.
#
# Then it verifies that <mounttable>.Glob(*) and <neighborhood>.Glob(nhname)
# return the correct result.
toplevel=$(git rev-parse --show-toplevel)
go=${toplevel}/scripts/build/go
thisscript=$0
echo "Test directory: $(dirname $0)"
builddir=$(mktemp -d --tmpdir=${toplevel}/go)
tmplog=$(mktemp)
trap onexit EXIT
onexit() {
cd /
exec 2> /dev/null
kill -9 $(jobs -p)
rm -rf $builddir $tmplog
}
FAIL() {
[ $# -gt 0 ] && echo "$thisscript $*"
echo FAIL
exit 1
}
PASS() {
echo PASS
exit 0
}
# Build mounttabled and mounttable binaries.
cd $builddir
$go build veyron/services/mounttable/mounttabled || FAIL "line $LINENO: failed to build mounttabled"
$go build veyron/tools/mounttable || FAIL "line $LINENO: failed to build mounttable"
# Start mounttabled and find its endpoint.
nhname=test$$
./mounttabled --address=localhost:0 --neighborhood_name=$nhname > $tmplog 2>&1 &
for i in 1 2 3 4; do
ep=$(grep "Mount table service at:" $tmplog | sed -re 's/^.*endpoint: ([^ ]*).*/\1/')
if [ -n "$ep" ]; then
break
fi
sleep 1
done
[ -z $ep ] && FAIL "line $LINENO: no server"
# Get the neighborhood endpoint from the mounttable.
nhep=$(./mounttable glob $ep nh | grep ^nh | cut -d' ' -f2)
[ -z $nhep ] && FAIL "line $LINENO: no neighborhood server"
# Mount objects and verify the result.
./mounttable mount "${ep}/myself" "$ep" 5m > /dev/null || FAIL "line $LINENO: failed to mount the mounttable on itself"
./mounttable mount "${ep}/google" /www.google.com:80 5m > /dev/null || FAIL "line $LINENO: failed to mount www.google.com"
# <mounttable>.Glob('*')
got=$(./mounttable glob $ep '*' | sed 's/TTL .m..s/TTL XmXXs/' | sort)
want="[${ep}]
google /www.google.com:80 (TTL XmXXs)
myself ${ep} (TTL XmXXs)
nh ${nhep} (TTL XmXXs)"
if [ "$got" != "$want" ]; then
FAIL "line $LINENO: unexpected output. Got $got, want $want"
fi
# <neighborhood>.Glob('nhname')
got=$(./mounttable glob $nhep $nhname | sed 's/TTL .m..s/TTL XmXXs/' | sort)
want="[${nhep}]
${nhname} ${ep} (TTL XmXXs)"
if [ "$got" != "$want" ]; then
FAIL "line $LINENO: unexpected output. Got $got, want $want"
fi
PASS