diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 05bcd35a..babb8213 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -514,10 +514,7 @@ update_repo() { git stash --all --quiet &> /dev/null || true # Okay for stash failure git clean --quiet --force -d || true # Okay for already clean directory # Pull the latest commits - if ! git branch | grep --quiet -E '^[*] [(](HEAD detached at|detached from) pull/[[:digit:]]+/merge[)]$'; then - # if tests are run with Github Actions, pulling changes will not be possible because of 'detached HEAD' state - git pull --no-rebase --quiet &> /dev/null || return $? - fi + git pull --no-rebase --quiet &> /dev/null || return $? # Check current branch. If it is master, then reset to the latest available tag. # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) curBranch=$(git rev-parse --abbrev-ref HEAD) diff --git a/test/conftest.py b/test/conftest.py index 7af82a63..2d388fdd 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -121,6 +121,41 @@ def mock_command(script, args, container): scriptlog=script)) +def mock_command_passthrough(script, args, container): + ''' + Per other mock_command* functions, allows intercepting of commands we don't want to run for real + in unit tests, however also allows only specific arguments to be mocked. Anything not defined will + be passed through to the actual command. + + Example use-case: mocking `git pull` but still allowing `git clone` to work as intended + ''' + orig_script_path = check_output('which {}'.format(script)) + full_script_path = '/usr/local/bin/{}'.format(script) + mock_script = dedent(r'''\ + #!/bin/bash -e + echo "\$0 \$@" >> /var/log/{script} + case "\$1" in'''.format(script=script)) + for k, v in args.items(): + case = dedent(''' + {arg}) + echo {res} + exit {retcode} + ;;'''.format(arg=k, res=v[0], retcode=v[1])) + mock_script += case + mock_script += dedent(r''' + *) + {orig_script_path} "\$@" + ;;'''.format(orig_script_path=orig_script_path)) + mock_script += dedent(''' + esac''') + container.run(''' + cat < {script}\n{content}\nEOF + chmod +x {script} + rm -f /var/log/{scriptlog}'''.format(script=full_script_path, + content=mock_script, + scriptlog=script)) + + def mock_command_run(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real diff --git a/test/test_automated_install.py b/test/test_automated_install.py index b2959337..304a8783 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -9,6 +9,7 @@ from .conftest import ( mock_command, mock_command_run, mock_command_2, + mock_command_passthrough, run_script ) @@ -153,6 +154,8 @@ def test_installPihole_fresh_install_readableFiles(Pihole): ''' # Whiptail dialog returns Cancel for user prompt mock_command('whiptail', {'*': ('', '0')}, Pihole) + # mock git pull + mock_command_passthrough('git', {'pull': ('', '0')}, Pihole) # mock systemctl to not start lighttpd and FTL mock_command_2( 'systemctl', @@ -396,6 +399,8 @@ def test_installPihole_fresh_install_readableBlockpage(Pihole, test_webpage): ] # Whiptail dialog returns Cancel for user prompt mock_command('whiptail', {'*': ('', '0')}, Pihole) + # mock git pull + mock_command_passthrough('git', {'pull': ('', '0')}, Pihole) # mock systemctl to start lighttpd and FTL ligthttpdcommand = dedent(r'''\"\" echo 'starting lighttpd with {}'