From 297d4eec57ae6be66b4bc28a274744c0516655a5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 15:44:31 -0800 Subject: [PATCH 01/15] Start test templates. --- automated install/basic-install.sh | 5 +++-- test/test_automated_install.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9fed0bca..1b643c18 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -701,8 +701,9 @@ update_pacakge_cache() { echo ":::" echo -n "::: Updating local cache of available packages..." - ${UPDATE_PKG_CACHE} &> /dev/null - echo " done!" + if ${UPDATE_PKG_CACHE}; then + echo " done!" + fi } notify_package_updates_available() { diff --git a/test/test_automated_install.py b/test/test_automated_install.py index f8e2ec3d..203c7521 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -274,6 +274,15 @@ def test_installPiholeWeb_already_populated_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_update_package_cache_success_no_errors(Pihole): + ''' confirms package cache was updated without any errors''' + updateCache = Pihole.run(''' + source /opt/pihole/basick-install.sh + update_pacakge_cache + ''') + assert 'Updating local cache of available packages...' in updateCache.stdout + assert 'done!' in updateCache.stdout + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 153a9d8ac71c51bdf4d211d2117af6fb123fa06d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 15:45:25 -0800 Subject: [PATCH 02/15] Start test templates. --- test/test_automated_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 203c7521..7f287c8f 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -277,7 +277,7 @@ def test_installPiholeWeb_already_populated_no_errors(Pihole): def test_update_package_cache_success_no_errors(Pihole): ''' confirms package cache was updated without any errors''' updateCache = Pihole.run(''' - source /opt/pihole/basick-install.sh + source /opt/pihole/basic-install.sh update_pacakge_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout From 96c59fada44ef451a979d41fe1df8c89d8d1ac81 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 15:47:27 -0800 Subject: [PATCH 03/15] Spelling check. --- automated install/basic-install.sh | 4 ++-- test/test_automated_install.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 1b643c18..003cd312 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -692,7 +692,7 @@ enable_service() { echo " done." } -update_pacakge_cache() { +update_package_cache() { #Running apt-get update/upgrade with minimal output can cause some issues with #requiring user input (e.g password for phpmyadmin see #218) @@ -1128,7 +1128,7 @@ main() { fi # Update package cache - update_pacakge_cache + update_package_cache # Notify user of package availability notify_package_updates_available diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 7f287c8f..c502aef6 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -278,7 +278,7 @@ def test_update_package_cache_success_no_errors(Pihole): ''' confirms package cache was updated without any errors''' updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh - update_pacakge_cache + update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout assert 'done!' in updateCache.stdout From f65a9dbfd281b3f7e37e3c63d50a06c52bce3929 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 15:49:28 -0800 Subject: [PATCH 04/15] Test for failure. --- test/test_automated_install.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index c502aef6..7096ad91 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -283,6 +283,16 @@ def test_update_package_cache_success_no_errors(Pihole): assert 'Updating local cache of available packages...' in updateCache.stdout assert 'done!' in updateCache.stdout +def test_update_package_cache_failure_no_errors(Pihole): + ''' confirms package cache was updated without any errors''' + mock_command(apt-get, {'*':('', '1')}, Pihole) + updateCache = Pihole.run(''' + source /opt/pihole/basic-install.sh + update_package_cache + ''') + assert 'Updating local cache of available packages...' in updateCache.stdout + assert 'done!' not in updateCache.stdout + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From f9cfed5aff68a53a062c225720bc3534d813d0f5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 15:56:43 -0800 Subject: [PATCH 05/15] Test for failure. --- test/test_automated_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 7096ad91..4ab6e3a3 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -285,7 +285,7 @@ def test_update_package_cache_success_no_errors(Pihole): def test_update_package_cache_failure_no_errors(Pihole): ''' confirms package cache was updated without any errors''' - mock_command(apt-get, {'*':('', '1')}, Pihole) + mock_command('apt-get', {'*':('', '1')}, Pihole) updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh update_package_cache From a7130e6530ac4fbf4b5649ef5aff7be21859418f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:03:48 -0800 Subject: [PATCH 06/15] Eval variable. (Not a fan.) --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 003cd312..9245ff81 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -701,7 +701,7 @@ update_package_cache() { echo ":::" echo -n "::: Updating local cache of available packages..." - if ${UPDATE_PKG_CACHE}; then + if eval ${UPDATE_PKG_CACHE}; then echo " done!" fi } From 737819b56e0d1cf736ac4cc8d73aa5273330f431 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:08:43 -0800 Subject: [PATCH 07/15] Populate all required variables with a distro check. --- test/test_automated_install.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 4ab6e3a3..04db4f1b 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -278,6 +278,7 @@ def test_update_package_cache_success_no_errors(Pihole): ''' confirms package cache was updated without any errors''' updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh + distro_check update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout @@ -288,6 +289,7 @@ def test_update_package_cache_failure_no_errors(Pihole): mock_command('apt-get', {'*':('', '1')}, Pihole) updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh + distro_check update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout From 585f8422066df137d2f288a39d2fd0ed7689ac5e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:33:40 -0800 Subject: [PATCH 08/15] Error check. --- automated install/basic-install.sh | 2 ++ test/test_automated_install.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9245ff81..00635e89 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -703,6 +703,8 @@ update_package_cache() { echo -n "::: Updating local cache of available packages..." if eval ${UPDATE_PKG_CACHE}; then echo " done!" + else + echo -n "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"" fi } diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 04db4f1b..29bb56d2 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -285,14 +285,15 @@ def test_update_package_cache_success_no_errors(Pihole): assert 'done!' in updateCache.stdout def test_update_package_cache_failure_no_errors(Pihole): - ''' confirms package cache was updated without any errors''' - mock_command('apt-get', {'*':('', '1')}, Pihole) + ''' confirms package cache was not updated''' + mock_command('apt-get', {'update':('', '1')}, Pihole) updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh distro_check update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout + assert 'ERROR' in updateCache.stdout assert 'done!' not in updateCache.stdout # Helper functions From 2d18b2d7846b154fa48f113efb6a805ce546ecc6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 15:44:31 -0800 Subject: [PATCH 09/15] Start test templates. --- automated install/basic-install.sh | 9 +++++---- test/test_automated_install.py | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9fed0bca..003cd312 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -692,7 +692,7 @@ enable_service() { echo " done." } -update_pacakge_cache() { +update_package_cache() { #Running apt-get update/upgrade with minimal output can cause some issues with #requiring user input (e.g password for phpmyadmin see #218) @@ -701,8 +701,9 @@ update_pacakge_cache() { echo ":::" echo -n "::: Updating local cache of available packages..." - ${UPDATE_PKG_CACHE} &> /dev/null - echo " done!" + if ${UPDATE_PKG_CACHE}; then + echo " done!" + fi } notify_package_updates_available() { @@ -1127,7 +1128,7 @@ main() { fi # Update package cache - update_pacakge_cache + update_package_cache # Notify user of package availability notify_package_updates_available diff --git a/test/test_automated_install.py b/test/test_automated_install.py index f8e2ec3d..c502aef6 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -274,6 +274,15 @@ def test_installPiholeWeb_already_populated_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_update_package_cache_success_no_errors(Pihole): + ''' confirms package cache was updated without any errors''' + updateCache = Pihole.run(''' + source /opt/pihole/basic-install.sh + update_package_cache + ''') + assert 'Updating local cache of available packages...' in updateCache.stdout + assert 'done!' in updateCache.stdout + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 2a5587f23677bc65667b89ed7af93c540422201c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 15:49:28 -0800 Subject: [PATCH 10/15] Test for failure. --- test/test_automated_install.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index c502aef6..4ab6e3a3 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -283,6 +283,16 @@ def test_update_package_cache_success_no_errors(Pihole): assert 'Updating local cache of available packages...' in updateCache.stdout assert 'done!' in updateCache.stdout +def test_update_package_cache_failure_no_errors(Pihole): + ''' confirms package cache was updated without any errors''' + mock_command('apt-get', {'*':('', '1')}, Pihole) + updateCache = Pihole.run(''' + source /opt/pihole/basic-install.sh + update_package_cache + ''') + assert 'Updating local cache of available packages...' in updateCache.stdout + assert 'done!' not in updateCache.stdout + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From a281d87315b4fea1ae3b4e023c050a3a1efe5ad9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:03:48 -0800 Subject: [PATCH 11/15] Eval variable. (Not a fan.) --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 003cd312..9245ff81 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -701,7 +701,7 @@ update_package_cache() { echo ":::" echo -n "::: Updating local cache of available packages..." - if ${UPDATE_PKG_CACHE}; then + if eval ${UPDATE_PKG_CACHE}; then echo " done!" fi } From 54e2c6181a5e5934f84453839e48b86be57712b1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:08:43 -0800 Subject: [PATCH 12/15] Populate all required variables with a distro check. --- test/test_automated_install.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 4ab6e3a3..04db4f1b 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -278,6 +278,7 @@ def test_update_package_cache_success_no_errors(Pihole): ''' confirms package cache was updated without any errors''' updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh + distro_check update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout @@ -288,6 +289,7 @@ def test_update_package_cache_failure_no_errors(Pihole): mock_command('apt-get', {'*':('', '1')}, Pihole) updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh + distro_check update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout From 409f76aa34ea4c3d3b53f87e29ca9854c90c300d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:33:40 -0800 Subject: [PATCH 13/15] Error check. --- automated install/basic-install.sh | 2 ++ test/test_automated_install.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9245ff81..00635e89 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -703,6 +703,8 @@ update_package_cache() { echo -n "::: Updating local cache of available packages..." if eval ${UPDATE_PKG_CACHE}; then echo " done!" + else + echo -n "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"" fi } diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 04db4f1b..29bb56d2 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -285,14 +285,15 @@ def test_update_package_cache_success_no_errors(Pihole): assert 'done!' in updateCache.stdout def test_update_package_cache_failure_no_errors(Pihole): - ''' confirms package cache was updated without any errors''' - mock_command('apt-get', {'*':('', '1')}, Pihole) + ''' confirms package cache was not updated''' + mock_command('apt-get', {'update':('', '1')}, Pihole) updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh distro_check update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout + assert 'ERROR' in updateCache.stdout assert 'done!' not in updateCache.stdout # Helper functions From 7291aa07cabccf2727577a505fb8d42465d05177 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:46:37 -0800 Subject: [PATCH 14/15] Silenc cache updater. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 00635e89..5540166f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -701,7 +701,7 @@ update_package_cache() { echo ":::" echo -n "::: Updating local cache of available packages..." - if eval ${UPDATE_PKG_CACHE}; then + if eval ${UPDATE_PKG_CACHE} &> /dev/null; then echo " done!" else echo -n "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"" From 439999cb6274a26985f8e6701bb2a0c5461beaf9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 16:47:53 -0800 Subject: [PATCH 15/15] Last rule check. --- test/test_automated_install.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 29bb56d2..89d9a0e0 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -282,6 +282,7 @@ def test_update_package_cache_success_no_errors(Pihole): update_package_cache ''') assert 'Updating local cache of available packages...' in updateCache.stdout + assert 'ERROR' not in updateCache.stdout assert 'done!' in updateCache.stdout def test_update_package_cache_failure_no_errors(Pihole):