Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_cekit(cwd, parameters=None, message=None, env=None):
if parameters is None:
parameters = ['build', '--dry-run', 'podman']
if env is None:
env = {}
with Chdir(cwd):
result = CliRunner(env=env).invoke(cli, parameters, catch_exceptions=False)
assert result.exit_code == 0
if message:
assert message in result.output
return result
def run_cekit(image_dir, args=None, descriptor=None):
if args is None:
args = ['build', '--dry-run', 'docker']
if descriptor is None:
descriptor = image_descriptor
with Chdir(image_dir):
with open('image.yaml', 'w') as fd:
yaml.dump(descriptor, fd, default_flow_style=False)
result = CliRunner().invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0
return result
def run_cekit(image_dir, args=None, env=None):
if args is None:
args = ['build', '--dry-run', 'docker']
if env is None:
env = {}
with Chdir(image_dir):
result = CliRunner(env=env).invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0
return result
def run_cekit(cwd,
parameters=['build', '--dry-run', 'docker'],
message=None, return_code=0):
with Chdir(cwd):
result = CliRunner().invoke(cli, parameters, catch_exceptions=False)
assert result.exit_code == return_code
if message:
assert message in result.output
return result
def run_cekit_return_dockerfile(mocker, workdir, argv, getservbyport=getservbyport_works):
# Do not try to validate dependencies while running tests, these are not neccessary
mocker.patch('cekit.generator.docker.DockerGenerator.dependencies').return_value({})
"""utility function to invoke cekit and return the generated Dockerfile"""
mocker.patch.object(socket, 'getservbyport', getservbyport)
with Chdir(str(workdir)):
if os.path.exists('target'):
shutil.rmtree('target')
CliRunner().invoke(cli, argv, catch_exceptions=False)
with open("target/image/Dockerfile", "r") as fd:
return fd.read()
def generate(image_dir, command, descriptor=None, exit_code=0):
desc = basic_config.copy()
if descriptor:
desc.update(descriptor)
tmp_image_file = os.path.join(image_dir, 'image.yaml')
with open(tmp_image_file, 'w') as outfile:
yaml.dump(desc, outfile, default_flow_style=False)
with Chdir(image_dir):
result = CliRunner().invoke(cli, command, catch_exceptions=False)
assert result.exit_code == exit_code
if exit_code != 0:
return
with open(os.path.join(image_dir, 'target', 'image.yaml'), 'r') as desc:
return yaml.safe_load(desc)
def test_custom_help_template_path(tmpdir, path_type):
help_template = os.path.join(str(tmpdir), "help.jinja")
if path_type == 'relative':
help_template = "help.jinja"
my_image_descriptor = image_descriptor.copy()
my_image_descriptor['help'] = {'template': help_template, 'add': True}
with Chdir(str(tmpdir)):
with open('help.jinja', "w") as fd:
fd.write(template_teststr)
with open('image.yaml', 'w') as fd:
yaml.dump(my_image_descriptor, fd, default_flow_style=False)
CliRunner().invoke(cli, ['-v', 'build', '--dry-run', 'docker'], catch_exceptions=False)
with open("target/image/help.md", "r") as fd:
contents = fd.read()
assert contents.find(template_teststr) >= 0
def repo_info(path):
with Chdir(path):
if subprocess.check_output(["git", "rev-parse", "--is-inside-work-tree"]).strip().decode("utf8") != "true":
raise Exception("Directory {} doesn't seem to be a git repository. "
"Please make sure you specified correct path.".format(path))
name = os.path.basename(subprocess.check_output(
["git", "rev-parse", "--show-toplevel"]).strip().decode("utf8"))
branch = subprocess.check_output(
["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode("utf8")
commit = subprocess.check_output(
["git", "rev-parse", "HEAD"]).strip().decode("utf8")
return name, branch, commit