mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-02-21 10:46:49 +00:00
Adding test to ensure upgrade vars are set, fixed
Modified upgrade variable import to export vars to ensure they stay set in all script scopes and environments
This commit is contained in:
parent
38c9434c62
commit
706e459d04
10 changed files with 127 additions and 3 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1 +1,5 @@
|
|||
.DS_Store
|
||||
*.pyc
|
||||
*.swp
|
||||
__pycache__
|
||||
.cache
|
||||
|
|
10
.travis.yml
Normal file
10
.travis.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
sudo: required
|
||||
services:
|
||||
- docker
|
||||
language: python
|
||||
python:
|
||||
- "2.7"
|
||||
install:
|
||||
- pip install -r requirements.txt
|
||||
|
||||
script: py.test -v
|
|
@ -803,6 +803,7 @@ finalExports() {
|
|||
${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars}
|
||||
${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars}
|
||||
${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars}
|
||||
export IPv4addr
|
||||
}
|
||||
|
||||
|
||||
|
@ -923,15 +924,18 @@ updateDialogs(){
|
|||
}
|
||||
|
||||
######## SCRIPT ############
|
||||
if [[ -f ${setupVars} ]];then
|
||||
. ${setupVars}
|
||||
if [ -f ${setupVars} ];then
|
||||
echo "::: Importing previous variables for upgrade"
|
||||
while read line; do
|
||||
echo " ::: ${line}"
|
||||
eval "export $line"
|
||||
done < ${setupVars}
|
||||
|
||||
if [ "$1" == "pihole" ]; then
|
||||
useUpdateVars=true
|
||||
else
|
||||
updateDialogs
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Start the installer
|
||||
|
|
1
autotest
Executable file
1
autotest
Executable file
|
@ -0,0 +1 @@
|
|||
py.test -v -f test/
|
13
pytest.Dockerfile
Normal file
13
pytest.Dockerfile
Normal file
|
@ -0,0 +1,13 @@
|
|||
FROM debian:jessie
|
||||
|
||||
ENV GITDIR /etc/.pihole
|
||||
ENV SCRIPTDIR /opt/pihole
|
||||
|
||||
RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole
|
||||
ADD . $GITDIR
|
||||
RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ && \
|
||||
rmdir /usr/local/bin && ln -s $SCRIPTDIR/ /usr/local/bin
|
||||
|
||||
RUN true && \
|
||||
sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \
|
||||
chmod +x $SCRIPTDIR/*
|
5
requirements.txt
Normal file
5
requirements.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
docker-compose
|
||||
pytest
|
||||
pytest-xdist
|
||||
pytest-cov
|
||||
testinfra
|
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
34
test/conftest.py
Normal file
34
test/conftest.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import pytest
|
||||
import testinfra
|
||||
|
||||
DEBUG = []
|
||||
|
||||
check_output = testinfra.get_backend(
|
||||
"local://"
|
||||
).get_module("Command").check_output
|
||||
|
||||
@pytest.fixture
|
||||
def Docker(request, args, image, cmd):
|
||||
assert 'docker' in check_output('id'), "Are you in the docker group?"
|
||||
docker_run = "docker run {} {} {}".format(args, image, cmd)
|
||||
docker_id = check_output(docker_run)
|
||||
|
||||
def teardown():
|
||||
check_output("docker rm -f %s", docker_id)
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
docker_container = testinfra.get_backend("docker://" + docker_id)
|
||||
docker_container.id = docker_id
|
||||
return docker_container
|
||||
|
||||
@pytest.fixture
|
||||
def args(request):
|
||||
return '-d'
|
||||
|
||||
@pytest.fixture()
|
||||
def image(request):
|
||||
return 'pytest_pihole'
|
||||
|
||||
@pytest.fixture()
|
||||
def cmd(request):
|
||||
return 'tail -f /dev/null'
|
17
test/test_000_build_containers.py
Normal file
17
test/test_000_build_containers.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
''' This file starts with 000 to make it run first '''
|
||||
import pytest
|
||||
import testinfra
|
||||
|
||||
run_local = testinfra.get_backend(
|
||||
"local://"
|
||||
).get_module("Command").run
|
||||
|
||||
@pytest.mark.parametrize("image,tag", [
|
||||
( 'pytest.Dockerfile', 'pytest_pihole' ),
|
||||
])
|
||||
def test_build_pihole_image(image, tag):
|
||||
build_cmd = run_local('docker build -f {} -t {} .'.format(image, tag))
|
||||
if build_cmd.rc != 0:
|
||||
print build_cmd.stdout
|
||||
print build_cmd.stderr
|
||||
assert build_cmd.rc == 0
|
36
test/test_automated_install.py
Normal file
36
test/test_automated_install.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def Pihole(Docker):
|
||||
''' generates stubs of files that normally execute code '''
|
||||
return Docker
|
||||
|
||||
def test_setupVars_get_read_into_main_scope_level(Pihole):
|
||||
vars = {
|
||||
'piholeInterface' : 'eth99',
|
||||
'IPv4addr' : '192.168.100.2',
|
||||
'piholeIPv6' : 'True',
|
||||
'piholeDNS1' : '4.2.2.1',
|
||||
'piholeDNS2' : '4.2.2.2'
|
||||
}
|
||||
setup_fake_vars = 'cat <<EOF> /etc/pihole/setupVars.conf\n'
|
||||
for k,v in vars.iteritems():
|
||||
setup_fake_vars += "{}={}\n".format(k, v)
|
||||
setup_fake_vars += "EOF\n"
|
||||
Pihole.run(setup_fake_vars).stdout
|
||||
#print Pihole.run('cat /etc/pihole/setupVars.conf').stdout
|
||||
|
||||
script = '/opt/pihole/stub_basic-install.sh pihole'
|
||||
|
||||
cmd = 'bash -c "\n'
|
||||
cmd += 'source {};\n'.format(script)
|
||||
cmd += 'env > /tmp/saved_env"\n'
|
||||
cmd += '"\n'
|
||||
stubbed_script = Pihole.run(cmd)
|
||||
env = Pihole.run('cat /tmp/saved_env').stdout
|
||||
print stubbed_script.stdout
|
||||
|
||||
assert "::: Importing previous variables for upgrade" in stubbed_script.stdout
|
||||
for k,v in vars.iteritems():
|
||||
assert "{}={}".format(k, v) in stubbed_script.stdout
|
||||
assert "{}={}".format(k, v) in env
|
Loading…
Add table
Reference in a new issue