mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add a test to ensure we don't check for fast-forward before fetching (#37571)
This commit is contained in:
parent
b01c247ea9
commit
2810b85cac
1 changed files with 63 additions and 0 deletions
|
@ -5,6 +5,7 @@ Tests for the Git state
|
|||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import errno
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
|
@ -334,6 +335,68 @@ class GitTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
|||
'branch (new_branch)'
|
||||
)
|
||||
|
||||
def test_latest_updated_remote_rev(self):
|
||||
'''
|
||||
Ensure that we don't exit early when checking for a fast-forward
|
||||
'''
|
||||
orig_cwd = os.getcwd()
|
||||
name = tempfile.mkdtemp(dir=integration.TMP)
|
||||
target = os.path.join(integration.TMP, 'test_latest_updated_remote_rev')
|
||||
|
||||
# Initialize a new git repository
|
||||
subprocess.check_call(['git', 'init', '--quiet', name])
|
||||
|
||||
try:
|
||||
os.chdir(name)
|
||||
# Set user.name and user.email config attributes if not present
|
||||
for key, value in (('user.name', 'Jenkins'),
|
||||
('user.email', 'qa@saltstack.com')):
|
||||
# Check if key is missing
|
||||
keycheck = subprocess.Popen(
|
||||
['git', 'config', '--get', key],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
if keycheck.wait() != 0:
|
||||
# Set the key if it is not present
|
||||
subprocess.check_call(
|
||||
['git', 'config', key, value])
|
||||
|
||||
# Add and commit a file
|
||||
with salt.utils.fopen('foo.txt', 'w') as fp_:
|
||||
fp_.write('Hello world\n')
|
||||
subprocess.check_call(['git', 'add', '.'])
|
||||
subprocess.check_call(['git', 'commit', '-qm', 'init'])
|
||||
|
||||
# Run the state to clone the repo we just created
|
||||
ret = self.run_state(
|
||||
'git.latest',
|
||||
name=name,
|
||||
target=target,
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
# Add another commit
|
||||
with salt.utils.fopen('foo.txt', 'w') as fp_:
|
||||
fp_.write('Added a line\n')
|
||||
subprocess.check_call(['git', 'commit', '-aqm', 'added a line'])
|
||||
|
||||
# Run the state again. It should pass, if it doesn't then there was
|
||||
# a problem checking whether or not the change is a fast-forward.
|
||||
ret = self.run_state(
|
||||
'git.latest',
|
||||
name=name,
|
||||
target=target,
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
finally:
|
||||
os.chdir(orig_cwd)
|
||||
for path in (name, target):
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.ENOENT:
|
||||
raise exc
|
||||
|
||||
def test_present(self):
|
||||
'''
|
||||
git.present
|
||||
|
|
Loading…
Add table
Reference in a new issue