Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split build and create integration tests #243

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/data/definition_files/no_galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
version: 1
dependencies:
galaxy: doesnotexist.yml
4 changes: 4 additions & 0 deletions test/data/definition_files/no_python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
version: 1
dependencies:
python: doesnotexist.txt
49 changes: 0 additions & 49 deletions test/integration/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
import os


def test_definition_syntax_error(cli, data_dir):
ee_def = os.path.join(data_dir, 'definition_files', 'invalid.yml')
r = cli(
f'ansible-builder build -f {ee_def} --container-runtime podman',
allow_error=True
)
assert r.rc != 0
assert 'An error occured while parsing the definition file' in (r.stdout + r.stderr), (r.stdout + r.stderr)


def test_build_fail_exitcode(cli, container_runtime, ee_tag, tmpdir, data_dir):
"""Test that when a build fails, the ansible-builder exits with non-zero exit code.

Expand All @@ -28,45 +18,6 @@ def test_build_fail_exitcode(cli, container_runtime, ee_tag, tmpdir, data_dir):
assert 'thisisnotacommand: command not found' in (r.stdout + r.stderr), (r.stdout + r.stderr)


def test_missing_python_requirements_file():
"""If a user specifies a python requirements file, but we can't find it, fail sanely."""
pytest.skip("Not implemented")


def test_missing_galaxy_requirements_file():
"""If a user specifies a galaxy requirements file, but we can't find it, fail sanely."""
pytest.skip("Not implemented")


def test_build_streams_output_with_verbosity_on(cli, container_runtime, build_dir_and_ee_yml, ee_tag):
"""Test that 'ansible-builder build' streams build output."""
tmpdir, eeyml = build_dir_and_ee_yml("")
result = cli(f"ansible-builder build -c {tmpdir} -f {eeyml} -t {ee_tag} --container-runtime {container_runtime} -v 3")
assert f'{container_runtime} build -f {tmpdir}' in result.stdout
assert f'Ansible Builder is building your execution environment image, "{ee_tag}".' in result.stdout
assert f'The build context can be found at: {tmpdir}' in result.stdout


def test_build_streams_output_with_verbosity_off(cli, container_runtime, build_dir_and_ee_yml, ee_tag):
"""
Like the test_build_streams_output_with_verbosity_on test but making sure less output is shown with default verbosity level of 2.
"""
tmpdir, eeyml = build_dir_and_ee_yml("")
result = cli(f"ansible-builder build -c {tmpdir} -f {eeyml} -t {ee_tag} --container-runtime {container_runtime}")
assert f'Ansible Builder is building your execution environment image, "{ee_tag}".' not in result.stdout
assert f'The build context can be found at: {tmpdir}' in result.stdout


def test_build_streams_output_with_invalid_verbosity(cli, container_runtime, build_dir_and_ee_yml, ee_tag):
"""
Like the test_build_streams_output_with_verbosity_off test but making sure it errors out correctly with invalid verbosity level.
"""
tmpdir, eeyml = build_dir_and_ee_yml("")
result = cli(f"ansible-builder build -c {tmpdir} -f {eeyml} -t {ee_tag} --container-runtime {container_runtime} -v 6", allow_error=True)
assert result.rc != 0
assert 'invalid choice: 6 (choose from 0, 1, 2, 3)' in (result.stdout + result.stderr)


def test_blank_execution_environment(cli, container_runtime, ee_tag, tmpdir, data_dir):
"""Just makes sure that the buld process does not require any particular input"""
bc = str(tmpdir)
Expand Down
52 changes: 52 additions & 0 deletions test/integration/test_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os


def test_definition_syntax_error(cli, data_dir):
ee_def = os.path.join(data_dir, 'definition_files', 'invalid.yml')
r = cli(f'ansible-builder create -f {ee_def}', allow_error=True)
assert r.rc != 0
assert 'An error occured while parsing the definition file' in (r.stdout + r.stderr), (r.stdout + r.stderr)


def test_missing_python_requirements_file(cli, data_dir):
"""If a user specifies a python requirements file, but we can't find it, fail sanely."""
ee_def = os.path.join(data_dir, 'definition_files', 'no_python.yml')
r = cli(f'ansible-builder create -f {ee_def}', allow_error=True)
assert r.rc != 0
assert 'does not exist' in (r.stdout + r.stderr), (r.stdout + r.stderr)


def test_missing_galaxy_requirements_file(cli, data_dir):
"""If a user specifies a galaxy requirements file, but we can't find it, fail sanely."""
ee_def = os.path.join(data_dir, 'definition_files', 'no_galaxy.yml')
r = cli(f'ansible-builder create -f {ee_def}', allow_error=True)
assert r.rc != 0
assert 'does not exist' in (r.stdout + r.stderr), (r.stdout + r.stderr)


def test_create_streams_output_with_verbosity_on(cli, build_dir_and_ee_yml):
"""Test that 'ansible-builder build' streams build output."""
tmpdir, eeyml = build_dir_and_ee_yml("")
result = cli(f"ansible-builder create -c {tmpdir} -f {eeyml} -v 3")
assert 'Ansible Builder is generating your execution environment build context.' in result.stdout
assert f'The build context can be found at: {tmpdir}' in result.stdout


def test_create_streams_output_with_verbosity_off(cli, build_dir_and_ee_yml):
"""
Like the test_create_streams_output_with_verbosity_on test but making sure less output is shown with default verbosity level of 2.
"""
tmpdir, eeyml = build_dir_and_ee_yml("")
result = cli(f"ansible-builder create -c {tmpdir} -f {eeyml}")
assert 'Ansible Builder is generating your execution environment build context.' not in result.stdout
assert f'The build context can be found at: {tmpdir}' in result.stdout


def test_create_streams_output_with_invalid_verbosity(cli, build_dir_and_ee_yml):
"""
Like the test_create_streams_output_with_verbosity_off test but making sure it errors out correctly with invalid verbosity level.
"""
tmpdir, eeyml = build_dir_and_ee_yml("")
result = cli(f"ansible-builder create -c {tmpdir} -f {eeyml} -v 6", allow_error=True)
assert result.rc != 0
assert 'invalid choice: 6 (choose from 0, 1, 2, 3)' in (result.stdout + result.stderr)