예제 #1
0
def test_bundle_add_file(path, expected_file_count):
    bundle = Bundle(chroot=chroot)
    assert len(
        bundle.files) == 0, 'The initial bundle should contain no files.'
    bundle.add_file(path)
    assert len(bundle.files) == expected_file_count, \
        'The bundle should include %d files.' % expected_file_count
예제 #2
0
def test_bundle_hash():
    bundle = Bundle(chroot=chroot)
    hashes = [bundle.hash]
    for filename in [fizz_buzz_glibc_32, fizz_buzz_glibc_64, fizz_buzz_musl_64]:
        bundle.add_file(filename)
        hashes.append(bundle.hash)
    assert len(hashes) == len(set(hashes)), 'All of the hashes should be unique.'
    assert all(len(hash) == 64 for hash in hashes), 'All of the hashes should have length 64.'
예제 #3
0
def test_bundle_file_factory():
    bundle = Bundle()
    bundle.add_file(ldd)
    # Note that `ldd` is a shell script, and should bring in no dependencies.
    [file] = bundle.files
    new_file = bundle.file_factory(ldd)
    assert new_file is file, \
        'The same file should be returned instead of making a new one.'
예제 #4
0
def test_bundle_root():
    try:
        bundle = Bundle(working_directory=True)
        assert bundle.hash in bundle.bundle_root, 'Bundle path should include the hash.'
        assert bundle.bundle_root.startswith(bundle.working_directory), \
            'The bundle root should be a subdirectory of the working directory.'
    except:  # noqa: E722
        raise
    finally:
        bundle.delete_working_directory()
예제 #5
0
def test_bundle_add_file_recursively():
    bundle = Bundle(chroot=chroot)
    assert len(bundle.files) == 0, 'The initial bundle should contain no files.'
    bundle.add_file(chroot)
    second_bundle = Bundle(chroot=chroot)
    for path in [ldd, fizz_buzz_glibc_32, fizz_buzz_glibc_32_exe, fizz_buzz_musl_64]:
        second_bundle.add_file(path)
    assert second_bundle.files.issubset(bundle.files), \
        'All of the executables and their dependencies should be in the first bundle.'
예제 #6
0
def test_bundle_delete_working_directory():
    bundle = Bundle()
    assert bundle.working_directory is None, \
        'A directory should only be created if passed `working_directory=True`.'
    bundle = Bundle(working_directory=True)
    working_directory = bundle.working_directory
    assert os.path.exists(working_directory), \
        'A working directory should have been created.'
    bundle.delete_working_directory()
    assert not os.path.exists(working_directory), \
        'The working directory should have been deleted.'
    assert bundle.working_directory is None, \
        'The working directory should have been cleared after deletion.'
예제 #7
0
def test_file_symlink():
    bundle = Bundle(chroot=chroot, working_directory=True)
    try:
        bundle.add_file(fizz_buzz_glibc_32)
        file = next(iter(bundle.files))
        file.copy(bundle.working_directory)
        symlink = file.symlink(bundle.working_directory, bundle.bundle_root)
        assert os.path.islink(symlink), 'A symlink should have been created.'
        assert os.path.exists(symlink), 'The symlink should point to the actual file.'
    except:  # noqa: E722
        raise
    finally:
        bundle.delete_working_directory()