import tempfile
import os
import shutil

import pytest

from ice_setup.ice import get_package_source, DirNotFound, VersionNotFound


@pytest.fixture
def pkg_path():
    pkg_path = tempfile.mkdtemp()

    def fin():
        shutil.rmtree(pkg_path)
    return pkg_path


class TestGetPackageSource(object):

    def test_unversioned_missing(self, pkg_path):
        with pytest.raises(DirNotFound):
            get_package_source(pkg_path, 'ceph')

    def test_unversioned_ok(self, pkg_path):
        os.mkdir(os.path.join(pkg_path, 'ceph'))
        path = get_package_source(pkg_path, 'ceph')
        assert path == os.path.join(pkg_path, 'ceph')

    def test_versioned_missing(self, pkg_path):
        os.mkdir(os.path.join(pkg_path, 'ceph'))
        with pytest.raises(VersionNotFound):
            get_package_source(pkg_path, 'ceph', traverse=True)

    def test_versioned_ok(self, pkg_path):
        os.makedirs(os.path.join(pkg_path, 'ceph/0.80.0'))
        path = get_package_source(pkg_path, 'ceph', traverse=True)
        assert path == os.path.join(pkg_path, 'ceph/0.80.0')

Add tests for package path building
Add tests for package path building

Unit tests for get_package_source()

Signed-off-by: Travis Rhoden <e5e44d6dbac12e32e01c3bb8b67940d8b42e225b@redhat.com>
