Skip to content

Commit

Permalink
Add test cases to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JayZ12138 committed Oct 23, 2019
1 parent c7a1689 commit e6ac02c
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 17 deletions.
52 changes: 52 additions & 0 deletions tests/data/ubi8/ubiconf_golang2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
content_sets:
rpm:
output: ubi-8-for-x86_64-appstream-rpms
input: rhel-8-for-x86_64-appstream-rpms
srpm:
output: ubi-8-for-x86_64-appstream-source-rpms
input: rhel-8-for-x86_64-appstream-source-rpms
debuginfo:
output: ubi-8-for-x86_64-appstream-debug-rpms
input: rhel-8-for-x86_64-appstream-debug-rpms

arches:
- src
- x86_64

packages:
include:
- go-srpm-macros.*
- go-toolset.*
- golang.*
- golang-bin.*
- golang-docs.*
- golang-misc.*
- golang-race.*
- golang-src.*
- golang-tests.*
exclude:
- python36
- kernel
- kernel-doc
- kmod-kvdo
- kernel.src
- kernel-debug-debuginfo
- kernel-debuginfo
- kernel-debuginfo-common-aarch64
- kernel-debuginfo-common-ppc64le
- kernel-debuginfo-common-s390x
- kernel-debuginfo-common-x86_64
- kernel-tools-debuginfo
- linux-firmware
- grub2
- grub2-common
- grub2-tools
- grub2-tools-minimal
- grubby
- redhat-release-eula
- s390utils-base

modules:
include:
- name: go-toolset
stream: rhel8
4 changes: 4 additions & 0 deletions tests/test_pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def fixture_search_repo_response():
"content_set": "test_repo-source-rpms",
"platform": "ubi",
"platform_full_version": "7",
"platform_major_version": "7",
"ubi_config_version": "7",
},
"distributors": [{
Expand All @@ -59,6 +60,7 @@ def fixture_mock_repo():
arch="x86_64",
content_set="test_repo-source-rpms",
platform_full_version="7",
platform_major_version="7",
ubi_config_version="7",
dist_ids_type_ids=[
("dist_id_1", "dist_type_id_1"),
Expand Down Expand Up @@ -186,6 +188,7 @@ def test_search_repo_by_cs(mock_pulp, mock_search_repos):
assert repo.arch == "x86_64"
assert repo.content_set == "test_repo-source-rpms"
assert repo.platform_full_version == "7"
assert repo.platform_major_version == "7"
assert repo.distributors_ids_type_ids_tuples[0] == ("dist_id", "d_type_id")
# ubi_population note was unset, so it should default to True
assert repo.ubi_population is True
Expand All @@ -201,6 +204,7 @@ def test_search_repo_by_id(mock_pulp, mock_search_repos):
assert repo.arch == "x86_64"
assert repo.content_set == "test_repo-source-rpms"
assert repo.platform_full_version == "7"
assert repo.ubi_config_version == "7"
assert repo.distributors_ids_type_ids_tuples[0] == ("dist_id", "d_type_id")
# ubi_population note was unset, so it should default to True
assert repo.ubi_population is True
Expand Down
56 changes: 55 additions & 1 deletion tests/test_ubipop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from mock import MagicMock, patch, call
from more_executors import Executors
from ubipop import UbiPopulateRunner, UbiRepoSet, RepoSet, UbiPopulate
from ubipop import UbiPopulateRunner, UbiRepoSet, RepoSet, UbiPopulate, ConfigMissing
from ubipop._pulp_client import Module, ModuleDefaults, Package, Repo
from ubipop._utils import (
AssociateActionModules,
Expand Down Expand Up @@ -72,6 +72,7 @@ def get_test_repo(**kwargs):
kwargs.get('arch'),
kwargs.get('content_set'),
kwargs.get('platform_full_version'),
kwargs.get('platform_major_version'),
kwargs.get('distributors_ids_type_ids'),
kwargs.get('ubi_population'),
kwargs.get('population_sources'),
Expand Down Expand Up @@ -195,6 +196,59 @@ def test_skip_outdated_dot_repos(mocked_search_repo_by_cs, mocked_ubipop_runner,
assert "ubi-8-for-x86_64-appstream-rpms" not in caplog.text
# Not for ubi-7-server
assert "ubi-7-server-rpms__7_DOT_2__x86_64" in caplog.text
# Used content sets won't be used again
assert "Skipping ubiconf_golang2.yaml, since it's been used already" in caplog.text


@patch("ubipop.UbiPopulateRunner")
@patch("ubipop._pulp_client.Pulp.search_repo_by_cs")
def test_raise_config_missing(mocked_search_repo_by_cs, mocked_ubipop_runner, caplog):
mocked_search_repo_by_cs.side_effect = [
# Output repos - rhel-7-for-x86_64-appstream
[get_test_repo(
repo_id="ubi-7-for-x86_64-appstream-rpms",
content_set="ubi-7-for-x86_64-appstream-rpms",
ubi_population=True,
platform_full_version="7",
platform_major_version="7"
), ],
[get_test_repo(
repo_id="ubi-7-for-x86_64-appstream-source-rpms",
content_set="ubi-7-for-x86_64-appstream-source-rpms",
ubi_population=True,
platform_full_version="7",
platform_major_version="7"
), ],
[get_test_repo(
repo_id="ubi-7-for-x86_64-appstream-debug-rpms",
content_set="ubi-7-for-x86_64-appstream-debug-rpms",
ubi_population=True,
platform_full_version="7",
platform_major_version="7"
), ],

# Input repos - rhel-7-for-x86_64-appstream
[get_test_repo(
repo_id="rhel-7-for-x86_64-appstream-rpms",
content_set="rhel-7-for-x86_64-appstream-rpms",
), ],
[get_test_repo(
repo_id="rhel-7-for-x86_64-appstream-source-rpms",
content_set="rhel-7-for-x86_64-appstream-source-rpms",
), ],
[get_test_repo(
repo_id="rhel-7-for-x86_64-appstream-debug-rpms",
content_set="rhel-7-for-x86_64-appstream-debug-rpms",
), ],
]
config_path = os.path.join(TEST_DATA_DIR, 'ubi8')
ubipop = UbiPopulate("foo.pulp.com", ("foo", "foo"), False, ubiconfig_dir_or_url=config_path)
with pytest.raises(ConfigMissing):
ubipop.populate_ubi_repos()

assert mocked_ubipop_runner.call_count == 0

assert "Config file ubiconf_golang.yaml missing from 7 and default 7 branches" in caplog.text


@patch("ubipop._pulp_client.Pulp.search_repo_by_id")
Expand Down
14 changes: 7 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

def test_raise_not_implemented_pulp_action():
units = ["unit1", "unit2"]
repo = Repo("test", "1", "test-rpms", "2", "2", None, None, None)
repo = Repo("test", "1", "test-rpms", "2", "2", "2", None, None, None)
action = PulpAction(units, repo)
pytest.raises(NotImplementedError, action.get_actions, None)


def test_raise_not_implemented_associate_action():
units = ["unit1", "unit2"]
repo = Repo("test", "1", "test-rpms", "2", "2", None, None, None)
src_repo = Repo("test", "1", "test-rpms", "2", "2", None, None, None)
repo = Repo("test", "1", "test-rpms", "2", "2", "2", None, None, None)
src_repo = Repo("test", "1", "test-rpms", "2", "2", "2", None, None, None)
action = AssociateAction(units, repo, src_repo)
pytest.raises(NotImplementedError, action.get_actions, None)

Expand All @@ -40,9 +40,9 @@ def test_get_action_associate(klass, method):
mocked_unit_2 = MagicMock()
mocked_unit_2.associate_source_repo_id = "test_src_2"
units = [mocked_unit_1, mocked_unit_2]
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", "2", None, None, None)
src_repos = [Repo("test_src_1", "1", "test_src-rpms", "2", "2", None, None, None),
Repo("test_src_2", "1", "test_src-rpms", "2", "2", None, None, None)]
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", "2", "2", None, None, None)
src_repos = [Repo("test_src_1", "1", "test_src-rpms", "2", "2", "2", None, None, None),
Repo("test_src_2", "1", "test_src-rpms", "2", "2", "2", None, None, None)]
action = klass(units, dst_repo, src_repos)
actions = action.get_actions(MagicMock())
for action in actions:
Expand All @@ -62,7 +62,7 @@ def test_get_action_associate(klass, method):
])
def test_get_action_unassociate(klass, method):
units = ["unit1", "unit2"]
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", "2", None, None, None)
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", "2", "2", None, None, None)
action = klass(units, dst_repo)
associate_action, dst_repo_current, current_units = action.get_actions(MagicMock())[0]

Expand Down
16 changes: 9 additions & 7 deletions ubipop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def _filter_ubi_conf_list(self, config_list, content_sets, repo_ids):

for conf in config_list:
for label in [
conf.content_sets.rpm.input, conf.content_sets.rpm.output,
conf.content_sets.srpm.input, conf.content_sets.srpm.output,
conf.content_sets.debuginfo.input, conf.content_sets.debuginfo.output,
conf.content_sets.rpm.input, conf.content_sets.rpm.output,
conf.content_sets.srpm.input, conf.content_sets.srpm.output,
conf.content_sets.debuginfo.input, conf.content_sets.debuginfo.output,
]:
if label in content_sets:
filtered_conf_list.append(conf)
Expand Down Expand Up @@ -171,10 +171,11 @@ def populate_ubi_repos(self):

for config in sorted(self.ubiconfig_list, key=str):
content_sets = [
config.content_sets.rpm,
config.content_sets.srpm,
config.content_sets.debuginfo
config.content_sets.rpm.output,
config.content_sets.srpm.output,
config.content_sets.debuginfo.output,
]

to_use = [cs for cs in content_sets if cs not in used_content_sets]
if to_use:
for cs in to_use:
Expand All @@ -193,6 +194,7 @@ def populate_ubi_repos(self):
for repo_set in repo_pairs:
ubi_config_version = repo_set.out_repos.rpm.ubi_config_version
platform_full_version = repo_set.out_repos.rpm.platform_full_version
platform_major_version = repo_set.out_repos.rpm.platform_major_version
# get the right config file by ubi_config_version attr, if it's None,
# then it's not a mainline repo, use platform_full_version instead.
# config file could also be missing for specific version, then the
Expand All @@ -202,7 +204,7 @@ def populate_ubi_repos(self):
.get(str(version), {})\
.get(config.file_name)\
or self.ubiconfig_map\
.get(str(platform_full_version), {})\
.get(str(platform_major_version), {})\
.get(config.file_name)

# if config file is missing from wanted version, as well as default
Expand Down
6 changes: 4 additions & 2 deletions ubipop/_pulp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def _search_repo(self, criteria):
arch=notes['arch'],
content_set=notes['content_set'],
platform_full_version=notes['platform_full_version'],
platform_major_version=notes['platform_major_version'],
dist_ids_type_ids=dist_info,
ubi_population=ubi_population,
population_sources=notes.get('population_sources'),
Expand Down Expand Up @@ -314,12 +315,13 @@ def publish_repo(self, repo):


class Repo(object):
def __init__(self, repo_id, arch, content_set, platform_full_version, dist_ids_type_ids,
ubi_population, population_sources, ubi_config_version):
def __init__(self, repo_id, arch, content_set, platform_full_version, platform_major_version,
dist_ids_type_ids, ubi_population, population_sources, ubi_config_version):
self.repo_id = repo_id
self.arch = arch
self.content_set = content_set
self.platform_full_version = platform_full_version
self.platform_major_version = platform_major_version
self.ubi_config_version = ubi_config_version
self.distributors_ids_type_ids_tuples = dist_ids_type_ids
self.ubi_population = ubi_population
Expand Down

0 comments on commit e6ac02c

Please sign in to comment.