Skip to content

Commit

Permalink
Add a simple integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskuehl committed Apr 28, 2017
1 parent e5cd6da commit 719d88d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import mock

import pytest

from lazy_build import cache
from lazy_build import config


Expand All @@ -15,6 +14,6 @@ def simple_config():
command=('touch venv'),
ignore={'*.py[co]'},
output={'venv'},
backend=mock.Mock(),
backend=cache.FilesystemBackend(path='cache'),
after_download=(),
)
71 changes: 71 additions & 0 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import json

import pytest

from lazy_build import main


@pytest.fixture
def simple_project(tmpdir):
tmpdir.join('.lazy-build.json').write(json.dumps({
'cache': {
'source': 'filesystem',
'path': 'cache',
},
}))
tmpdir.join('cache').mkdir()
tmpdir.join('input').write('first input\n')
tmpdir.join('test.sh').write(
'echo ohai\n'
'cat input > output1\n'
'mkdir -p output2\n'
'echo asdf > output2/thing\n'
)
with tmpdir.as_cwd():
yield tmpdir


def test_typical_flow(simple_project, capfd):
"""Test that it correctly caches based on the inputs."""
args = (
'build',
'context=', 'input',
'output=', 'output1', 'output2',
'command=', 'bash', 'test.sh',
)

def cleanup():
simple_project.join('output1').remove()
simple_project.join('output2').remove()

# The first run shouldn't be cached.
main.main(args)
out, err = capfd.readouterr()
assert out == 'ohai\n'
assert simple_project.join('output1').read() == 'first input\n'
assert simple_project.join('output2', 'thing').read() == 'asdf\n'

# The second run should be cached.
cleanup()
main.main(args)
out, err = capfd.readouterr()
assert out == ''
assert simple_project.join('output1').read() == 'first input\n'
assert simple_project.join('output2', 'thing').read() == 'asdf\n'

# If we change the input, it shouldn't be cached anymore.
cleanup()
simple_project.join('input').write('second input\n')
main.main(args)
out, err = capfd.readouterr()
assert out == 'ohai\n'
assert simple_project.join('output1').read() == 'second input\n'
assert simple_project.join('output2', 'thing').read() == 'asdf\n'

# But the next run with the same input should be cached.
cleanup()
main.main(args)
out, err = capfd.readouterr()
assert out == ''
assert simple_project.join('output1').read() == 'second input\n'
assert simple_project.join('output2', 'thing').read() == 'asdf\n'

0 comments on commit 719d88d

Please sign in to comment.