Example #1
0
def test_debian_build_lang_c(local_repo_dir: Path, asset_dir: Path,
                             docker_from: str):
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=asset_dir,
        docker_from=docker_from,
    )
    image = bldr.build(asset_dir.joinpath('example-lang-C'))

    local_deb_files = get_local_deb_files(local_repo_dir,
                                          package_prefix='dummy_1.0-1_amd64')
    assert len(local_deb_files
               ) == 1, "one debian package should match to the glob pattern"

    with bldr._create_container(image) as container:
        output = container.exec_run(
            command=['dpkg', '--contents', local_deb_files[0]])
        deb_content = '\n'.join(
            sorted([line.split()[5] for line in output.strip().split('\n')]))
        expected_content = asset_dir.joinpath(
            'expected.example-lang-c.contents').read_text()
        assert deb_content == expected_content, "Deb file should contain the expected files"

        output = container.exec_run(
            command=['dpkg', '--field', local_deb_files[0]])
        assert 'Package: dummy' in output, "package name should be in the debian fields"
        assert "Version: 1.0-1" in output, "version field should be in the debian fields in the given format"
        assert 'Maintainer: Test Maintainer <*****@*****.**>' in output, "maintaner should be in the debian fields"
Example #2
0
def test_snapshot_version(local_repo_dir: Path, asset_dir: Path,
                          docker_from: str):
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=asset_dir,
        docker_from=docker_from,
        snapshot=True,
    )
    image = bldr.build(asset_dir.joinpath('example-lang-C'))

    with bldr._create_container(image) as container:
        local_deb_files = get_local_deb_files(
            local_repo_dir, package_prefix='dummy_1.0-1+xsnapshot')
        assert len(
            local_deb_files
        ) == 1, "one debian package should match to the glob pattern"

        output = container.exec_run(
            command=['dpkg', '--contents', local_deb_files[0]])
        deb_content = '\n'.join(
            sorted([line.split()[5] for line in output.strip().split('\n')]))
        expected_content = asset_dir.joinpath(
            'expected.example-lang-c.contents').read_text()
        assert deb_content == expected_content, "Deb file should contain the expected files"

        output = container.exec_run(
            command=['dpkg', '--field', local_deb_files[0]])
        assert 'Package: dummy' in output, "package name should be in the debian fields"
        assert re.search(
            r"^Version: 1\.0-1\+xsnapshot\+\d{4}(?:\.\d{2}){5}\+1$",
            output,
            flags=re.MULTILINE
        ), "version field should be in the debian fields in the given format"
        assert 'Maintainer: Test Maintainer <*****@*****.**>' in output, "maintaner should be in the debian fields"
Example #3
0
def test_symlinks(local_repo_dir: Path, asset_dir: Path, docker_from: str):
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=asset_dir,
        docker_from=docker_from,
    )
    bldr.build(asset_dir.joinpath('symlinks'))
Example #4
0
def test_build_fails(local_repo_dir: Path, asset_dir: Path, docker_from: str):
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=asset_dir,
        docker_from=docker_from,
    )
    with pytest.raises(BLDRError):
        bldr.build(asset_dir.joinpath('never-builds'))
        pytest.fail(
            "SBS should raise exception, when an error occurs during build.")
Example #5
0
def test_debian_build_with_hooks(local_repo_dir: Path, asset_dir: Path,
                                 docker_from: str):
    bldr = BLDR(local_repo_dir=local_repo_dir,
                source_dir=asset_dir,
                docker_from=docker_from,
                hooks_dir=asset_dir.joinpath('test-hooks'))
    bldr.build(asset_dir.joinpath('example-lang-C'))

    assert local_repo_dir.joinpath(
        'pre-build.called').exists(), "pre-build hook should be called"
    assert local_repo_dir.joinpath(
        'pre-init.called').exists(), "pre-init hook should be called"
    assert local_repo_dir.joinpath('pre-install-deps.called').exists(
    ), "pre-install-deps hook should be called"
    assert local_repo_dir.joinpath('post-install-deps.called').exists(
    ), "post-install-deps hook should be called"
Example #6
0
def test_depencies_are_satisfied_using_local_apt(local_repo_dir: Path,
                                                 asset_dir: Path,
                                                 docker_from: str):
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=asset_dir,
        docker_from=docker_from,
    )
    bldr.build(asset_dir.joinpath('libdependable'))
    image = bldr.build(asset_dir.joinpath('depend-test'))

    with bldr._create_container(image) as container:
        local_deb_files = get_local_deb_files(local_repo_dir)
        container.exec_run(['sudo', 'dpkg', '-i'] + local_deb_files)
        output = container.exec_run(['run-depend-test'])
        assert re.search(
            r"^I am", output, flags=re.MULTILINE
        ), "run-depend-test output should contain the given string"
Example #7
0
def test_reindex(asset_dir: Path, reindex_data: Path, tmp_path: Path,
                 docker_from: str):
    bldr = BLDR(
        local_repo_dir=reindex_data,
        source_dir=tmp_path,
        docker_from=docker_from,
    )
    bldr.reindex()

    expected_packages_content = asset_dir.joinpath(
        'test-reindex-data', 'Packages.correct').read_text()
    assert reindex_data.joinpath('Packages').read_text(
    ) == expected_packages_content, 'Generated Packages file should be identical to Packages.correct'

    expected_sources_content = asset_dir.joinpath(
        'test-reindex-data', 'Sources.correct').read_text()
    assert reindex_data.joinpath('Sources').read_text(
    ) == expected_sources_content, 'Generated Sources file should be identical to Sources.correct'
Example #8
0
def test_git_project_debian_build(local_repo_dir: Path, git_project_path: Path,
                                  docker_from: str):
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=git_project_path.parent,
        docker_from=docker_from,
    )
    bldr.build(git_project_path)

    dsc_file_path = local_repo_dir.joinpath('git_project', 'debs',
                                            'git-proj_2.3-4.dsc')
    assert dsc_file_path, "Built dsc file should be in the local repo directory"

    dsc_file_content = dsc_file_path.read_text()
    assert "Vcs-Git: http://example.com/test-git-proj.git" in dsc_file_content

    commit_id = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
                                        cwd=git_project_path).decode('utf-8')
    assert "Vcs-Git-Commit-Id: {}".format(commit_id) in dsc_file_content
Example #9
0
def do_build(local_repo_dir: Path, quilt_project_path: Path, docker_from: str,
             tmp_path: Path, expected_output: str) -> None:
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=quilt_project_path.parent,
        docker_from=docker_from,
    )
    bldr.build(quilt_project_path)

    quilt_proj_deb_file = list(local_repo_dir.glob('**/quilt-proj*.deb'))[0]

    extract_dir = tmp_path.joinpath('extracted')
    extract_dir.mkdir()
    extract_deb(quilt_proj_deb_file, extract_dir)

    output = subprocess.check_output(['usr/bin/am-i-quilted'],
                                     cwd=extract_dir).decode('utf-8')
    assert output == expected_output, "The script output should be what expected"

    shutil.rmtree(str(extract_dir), ignore_errors=True)
Example #10
0
def test_quilt_project_build(local_repo_dir: Path, quilt_project_path: Path,
                             docker_from: str, tmp_path: Path):
    bldr = BLDR(
        local_repo_dir=local_repo_dir,
        source_dir=quilt_project_path.parent,
        docker_from=docker_from,
    )
    bldr.build(quilt_project_path)

    quilt_proj_deb_file = list(local_repo_dir.glob('**/quilt-proj*.deb'))[0]

    extract_dir = tmp_path.joinpath('extracted')
    extract_dir.mkdir()
    extract_deb(quilt_proj_deb_file, extract_dir)

    content = extract_dir.joinpath('usr', 'share', 'doc', 'feeling',
                                   'alone').read_text()
    assert content == "Hello, friend!\n", "The patched file should be correct."

    content = extract_dir.joinpath('usr', 'share', 'doc', 'feeling',
                                   'lonely').read_text()
    assert content == "I am a test.\n", "The patched file should be correct."