Skip to content

Commit

Permalink
Add tests to the VGP xlator
Browse files Browse the repository at this point in the history
  • Loading branch information
dleonard committed Sep 19, 2008
1 parent 5e648f4 commit 525730f
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ MachineXlators_SCRIPTS = quest-dnsupdate-xlator
quest-dnsupdate-xlator: xlator.sh.in
$(SUBST) <$(srcdir)/xlator.sh.in > $@
chmod +x $@
EXTRA_DIST += xlator.sh.in
CLEANFILES += quest-dnsupdate-xlator

xlator-t: xlator-t.sh
cat $(srcdir)/xlator-t.sh > $@
chmod +x $@
check_PROGRAMS += xlator-t
EXTRA_DIST += xlator.sh.in xlator-t.sh
CLEANFILES += quest-dnsupdate-xlator xlator-t
128 changes: 128 additions & 0 deletions xlator-t.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/sh

XLATOR="./quest-dnsupdate-xlator -test"
WRKTMP=${TMPDIR:-/tmp}/.xlator-t$$

mkdir -p $WRKTMP
#trap 'rm -rf $WRKTMP' 0
VERBOSE=false
PASSED_ALL=true

# XXX tests go here

verbose () { $VERBOSE && echo "$*"; :; }
start () { TESTNAME="$*"; }
result () { if test $? = 0; then pass; else fail; fi; }
invert () { test $? != 0; "$@"; }
pass () { echo " ok $TESTNAME"; }
fail () { echo "FAIL $TESTNAME"; PASSED_ALL=false; }

#-- runs the given command, and returns true if the here-document on
# file descriptor 3 matches the output from the given command
check () {
expected_ec=0
case $1 in -exit) shift; expected_ec=$1; shift;; esac

cat <&3 > $WRKTMP/expected
"$@" > $WRKTMP/out; ec=$?

if test $ec != $expected_ec; then
echo "unexpected exit code from '$*'" >&2
echo " was $ec, expected $expected_ec" >&2
return 1
fi

if cmp -s $WRKTMP/expected $WRKTMP/out; then
:
else
{ echo "unexpected output from '$*'"
echo "----- actual output:"
cat $WRKTMP/out
echo "----- expected output:"
cat $WRKTMP/expected
} >&2
return 1
fi
return 0
}

cat <<-. > $WRKTMP/input
Software\Policies\Microsoft\Windows NT\DNSClient;RegistrationEnabled;REG_DWORD;1
Software\Policies\Microsoft\Windows NT\DNSClient;RegisterReverseLookup;REG_DWORD;2
Software\Policies\Microsoft\Windows NT\DNSClient;RegistrationOverwritesInConflict;REG_DWORD;0
Software\Policies\Microsoft\Windows NT\DNSClient;RegistrationTtl;REG_DWORD;600
Software\Policies\Microsoft\Windows NT\DNSClient;UpdateSecurityLevel;REG_DWORD;0
Software\Policies\Microsoft\Windows NT\DNSClient;UpdateTopLevelDomainZones;REG_DWORD;0
.

start "info"
$XLATOR info >/dev/null </dev/null
result

start "badarg"
$XLATOR badarg >/dev/null </dev/null 2>&1
invert result

start "keys"
check $XLATOR keys </dev/null 3<<'.'
Software\Policies\Microsoft\Windows NT\DNSClient
.
result

CONF=/tmp/dnsupdate.conf

start "init from empty"
rm -f $CONF &&
check $XLATOR init </dev/null 3</dev/null &&
test ! -f $CONF
result

start "apply"
check $XLATOR <$WRKTMP/input 3</dev/null &&
check cat $CONF 3<<'.'
#--VGP BEGIN--#
RegisterReverseLookup = 2
RegistrationEnabled = 1
RegistrationOverwritesInConflict = 0
RegistrationTtl = 600
UpdateSecurityLevel = 0
UpdateTopLevelDomainZones = 0
#--VGP END--#
.
result

start "init to empty"
check $XLATOR init </dev/null 3</dev/null &&
test ! -f $CONF
result

cat <<. >$CONF
# Some random existing conf file
Foo = 1 2 3
UpdateSecurityLevel = 99999
.

start "apply existing"
cp $CONF $WRKTMP/orig.conf
cp $WRKTMP/orig.conf $WRKTMP/expect.conf
cat >>$WRKTMP/expect.conf <<-.
#--VGP BEGIN--#
RegisterReverseLookup = 2
RegistrationEnabled = 1
RegistrationOverwritesInConflict = 0
RegistrationTtl = 600
UpdateSecurityLevel = 0
UpdateTopLevelDomainZones = 0
#--VGP END--#
.
check $XLATOR <$WRKTMP/input 3</dev/null &&
check cat $CONF 3<$WRKTMP/expect.conf
result

start "init existing"
check $XLATOR init </dev/null 3</dev/null &&
check cat $CONF 3<$WRKTMP/orig.conf
result

$PASSED_ALL # must be last line
22 changes: 19 additions & 3 deletions xlator.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,25 @@ SAVEDIR=/var/opt/quest/vgp/exts/admext/quest-dnsupdate
CONF="@sysconfdir@/dnsupdate.conf"
CONFTMP=/tmp/.$$dnsupdate.conf.tmp

#-- When run with -test flag, write to /tmp
case $1 in
-test)
shift
SAVEDIR=/tmp/savedir
CONF=/tmp/dnsupdate.conf
mkdir -p $SAVEDIR
;;
esac


case $1 in
info)
echo "quest-dnsupdate xlator"
cat <<-.
INFO: $0
This translator configures quest-dnsupdate in accordance with
the policies defined for Microsoft DNS Client.
.
;;
keys)
cat <<-'.'
Expand Down Expand Up @@ -42,7 +58,7 @@ case $1 in
if test -s $CONFTMP.2; then
{ test -s $CONF && cat $CONF
echo '#--VGP BEGIN--#'
cat $CONFTMP.2
sort < $CONFTMP.2
echo '#--VGP END--#'
} > $CONFTMP.3
cat $CONFTMP.3 > $CONF
Expand All @@ -53,5 +69,5 @@ case $1 in
echo "unknown argument '$1'" >&2
exit 1
;;
fi
esac
:

0 comments on commit 525730f

Please sign in to comment.