Download tests.

Make sure we download a binary and not just get the GitHub page.

Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
Dan Schaper 2017-02-20 09:36:24 -08:00
parent 7a269e757e
commit 70e876ee13
No known key found for this signature in database
GPG key ID: 572E999E385B7BFC
2 changed files with 35 additions and 10 deletions

View file

@ -1164,17 +1164,19 @@ FTLinstall() {
echo "::: failed (error in getting latest release location from GitHub)" echo "::: failed (error in getting latest release location from GitHub)"
return 1 return 1
fi fi
if curl -sSL --fail "${latestURL}${binary}" -o "/tmp/pihole-FTL"; then if curl -sSL --fail "${latestURL%$'\r'}/${binary}" -o "/tmp/pihole-FTL"; then
echo "::: done" if [[ -f /tmp/pihole-FTL ]]; then
install -m 0755 /tmp/pihole-FTL /usr/bin echo "::: done"
touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port install -m 0755 /tmp/pihole-FTL /usr/bin
chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port
return 0 chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port
else return 0
echo "::: failed (download of binary from Github failed)" else
return 1 echo "::: failed (download of binary from Github failed)"
return 1
fi
echo "done"
fi fi
echo "done"
} }
FTLdetect() { FTLdetect() {

View file

@ -355,6 +355,29 @@ def test_FTL_detect_unknown_no_errors(Pihole):
''') ''')
expected_stdout = 'Not able to detect architecture (unknown: mips)' expected_stdout = 'Not able to detect architecture (unknown: mips)'
assert expected_stdout in detectPlatform.stdout assert expected_stdout in detectPlatform.stdout
def test_FTL_download_aarch64_no_errors(Pihole):
''' confirms only aarch64 package is downloaded for FTL engine '''
# mock uname to return generic platform
download_binary = Pihole.run('''
source /opt/pihole/basic-install.sh
FTLinstall pihole-FTL-aarch64-linux-gnu
''')
expected_stdout = 'done'
assert expected_stdout in download_binary.stdout
assert 'failed' not in download_binary.stdout
def test_FTL_download_unknown_fails_no_errors(Pihole):
''' confirms unknown binary is not downloaded for FTL engine '''
# mock uname to return generic platform
download_binary = Pihole.run('''
source /opt/pihole/basic-install.sh
FTLinstall pihole-FTL-mips
''')
expected_stdout = 'failed'
assert expected_stdout in download_binary.stdout
assert 'done' not in download_binary.stdout
# Helper functions # Helper functions
def mock_command(script, args, container): 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 ''' ''' Allows for setup of commands we don't really want to have to run for real in unit tests '''