fix debian test_pihole_start_cmd

This commit is contained in:
diginc 2017-12-07 20:27:06 -06:00
parent 6ff1d21f7b
commit aab0b3f3cb
4 changed files with 15 additions and 12 deletions

View File

@ -276,7 +276,7 @@ test_framework_stubbing() {
if [ -n "$PYTEST" ] ; then if [ -n "$PYTEST" ] ; then
echo ":::::: Tests are being ran - stub out ad list fetching and add a fake ad block" echo ":::::: Tests are being ran - stub out ad list fetching and add a fake ad block"
sed -i 's/^gravity_spinup$/#gravity_spinup # DISABLED FOR PYTEST/g' "$(which gravity.sh)" sed -i 's/^gravity_spinup$/#gravity_spinup # DISABLED FOR PYTEST/g' "$(which gravity.sh)"
echo 'testblock.pi-hole.local' >> /etc/pihole/blacklist.txt echo 'testblock.pi-hole.local' >> /etc/pihole/black.list
fi fi
} }

View File

@ -46,7 +46,7 @@ if [[ "$TAG" == 'debian' ]] ; then
# IPv6 support for nc openbsd better than traditional # IPv6 support for nc openbsd better than traditional
apt-get install -y --force-yes netcat-openbsd apt-get install -y --force-yes netcat-openbsd
elif [[ "$TAG" == 'alpine' ]] ; then elif [[ "$TAG" == 'alpine' ]] ; then
apk add \ apk add -U \
dnsmasq \ dnsmasq \
nginx \ nginx \
ca-certificates \ ca-certificates \

View File

@ -8,7 +8,7 @@ check_output = testinfra.get_backend(
def DockerGeneric(request, args, image, cmd): def DockerGeneric(request, args, image, cmd):
assert 'docker' in check_output('id'), "Are you in the docker group?" assert 'docker' in check_output('id'), "Are you in the docker group?"
if 'pi-hole' in image: if 'pi-hole' in image:
args += " --dns 127.0.0.1 -v /dev/null:/etc/.pihole/adlists.default -e PYTEST=\"True\"" args += " --dns 127.0.0.1 -v /dev/null:/etc/pihole/adlists.default -e PYTEST=\"True\""
docker_run = "docker run -d {} {} {}".format(args, image, cmd) docker_run = "docker run -d {} {} {}".format(args, image, cmd)
print docker_run print docker_run
docker_id = check_output(docker_run) docker_id = check_output(docker_run)

View File

@ -10,6 +10,7 @@ def RunningPiHole(DockerPersist, Slow, persist_webserver, persist_tag, start_cmd
''' Override the RunningPiHole to run and check for success of a ''' Override the RunningPiHole to run and check for success of a
dnsmasq start based `pihole` script command ''' dnsmasq start based `pihole` script command '''
#print DockerPersist.run('ps -ef').stdout #print DockerPersist.run('ps -ef').stdout
assert DockerPersist.dig.run('ping -c 1 test_pihole').rc == 0
Slow(lambda: DockerPersist.run('pgrep dnsmasq').rc == 0) Slow(lambda: DockerPersist.run('pgrep dnsmasq').rc == 0)
Slow(lambda: DockerPersist.run('pgrep {}'.format(persist_webserver)).rc == 0) Slow(lambda: DockerPersist.run('pgrep {}'.format(persist_webserver)).rc == 0)
oldpid = DockerPersist.run('pidof dnsmasq') oldpid = DockerPersist.run('pidof dnsmasq')
@ -30,15 +31,17 @@ def test_pihole_start_cmd(RunningPiHole, start_cmd, persist_tag):
''' the start_cmd tests are all built into the RunningPiHole fixture in this file ''' ''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
assert RunningPiHole.cmd.stdout == START_DNS_STDOUT[persist_tag] assert RunningPiHole.cmd.stdout == START_DNS_STDOUT[persist_tag]
@pytest.mark.parametrize('start_cmd,hostname,expected_ip, expected_message', [ @pytest.mark.parametrize('start_cmd,hostname,expected_ip, expected_messages', [
('enable', 'pi.hole', '127.0.0.1', 'enabled'), ('enable', 'pi.hole', '127.0.0.1', ['Enabling blocking','Pi-hole Enabled']),
('disable 0', 'pi.hole', '127.0.0.1', 'disabled'), ('disable', 'pi.hole', '127.0.0.1', ['Disabling blocking','Pi-hole Disabled']),
]) ])
def test_pihole_start_cmd(RunningPiHole, Dig, persist_tag, start_cmd, hostname, expected_ip, expected_message): def test_pihole_start_cmd(RunningPiHole, Dig, persist_tag, start_cmd, hostname, expected_ip, expected_messages):
''' the start_cmd tests are all built into the RunningPiHole fixture in this file ''' ''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
dig_cmd = "dig +time=1 +noall +answer {} @test_pihole | awk '{{ print $5 }}'".format(hostname) dig_cmd = "dig +time=1 +noall +answer {} @test_pihole".format(hostname)
lookup = RunningPiHole.dig.run(dig_cmd).stdout.rstrip('\n') lookup = RunningPiHole.dig.run(dig_cmd)
assert lookup == expected_ip assert lookup.rc == 0
lookup_ip = lookup.stdout.split()[4]
assert lookup_ip == expected_ip
stdout = "::: Blocking has been {}!\n".format(expected_message) for part_of_output in expected_messages:
assert stdout in RunningPiHole.cmd.stdout assert part_of_output in RunningPiHole.cmd.stdout