Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Add unit test docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
locriandev committed Dec 6, 2022
1 parent 78ef274 commit 8b52cab
Showing 1 changed file with 98 additions and 5 deletions.
103 changes: 98 additions & 5 deletions tests/cli/test_gen_assembly.py
@@ -1,35 +1,49 @@
from unittest import TestCase
from unittest.mock import MagicMock, Mock, patch
from unittest.mock import MagicMock, patch

from flexmock import flexmock

import doozerlib
from doozerlib.assembly import AssemblyIssueCode, AssemblyTypes, AssemblyIssue
from doozerlib.assembly import AssemblyTypes
from doozerlib.cli.release_gen_assembly import GenAssemblyCli


class TestGenPayloadCli(TestCase):

def test_initialize_assembly_type(self):
"""
Check that the correct assembly type is set, according to
the gen-assembly name or `custom` flag
"""

runtime = MagicMock()

# If `custom` flag is set to true, assembly type should be CUSTOM
gacli = GenAssemblyCli(runtime=runtime, custom=True)
self.assertEqual(gacli.assembly_type, AssemblyTypes.CUSTOM)

# For RC gen-assembly names, assembly type should be CANDIDATE
gacli = GenAssemblyCli(runtime=runtime, gen_assembly_name='rc.0')
self.assertEqual(gacli.assembly_type, AssemblyTypes.CANDIDATE)

# For FC gen-assembly names, assembly type should be CANDIDATE
gacli = GenAssemblyCli(runtime=runtime, gen_assembly_name='fc.0')
self.assertEqual(gacli.assembly_type, AssemblyTypes.CANDIDATE)

# For EC gen-assembly names, assembly type should be PREVIEW
gacli = GenAssemblyCli(runtime=runtime, gen_assembly_name='ec.0')
self.assertEqual(gacli.assembly_type, AssemblyTypes.PREVIEW)

# For any other non-standardard gen-assembly names, assembly type should be STANDARD
gacli = GenAssemblyCli(runtime=runtime, gen_assembly_name='just-a-name')
self.assertEqual(gacli.assembly_type, AssemblyTypes.STANDARD)

@patch('doozerlib.cli.release_gen_assembly.GenAssemblyCli._exit_with_error', MagicMock(return_value=None))
def test_non_stream_assembly_name(self):
"""
Check that assembly must be "stream" in order to populate an assembly definition from nightlies.
The command should raise an error otherwise
"""

gacli = flexmock(GenAssemblyCli(
runtime=MagicMock(assembly='custom', arches=['amd64']),
nightlies=['4.13.0-0.nightly-2022-12-01-153811']
Expand All @@ -39,6 +53,11 @@ def test_non_stream_assembly_name(self):

@patch('doozerlib.cli.release_gen_assembly.GenAssemblyCli._exit_with_error', MagicMock(return_value=None))
def test_no_nightlies_nor_standards(self):
"""
At least one release (--nightly or --standard) must be specified.
The command should raise an error otherwise
"""

gacli = flexmock(GenAssemblyCli(
runtime=MagicMock(assembly='stream')
))
Expand All @@ -47,6 +66,12 @@ def test_no_nightlies_nor_standards(self):

@patch('doozerlib.cli.release_gen_assembly.GenAssemblyCli._exit_with_error', MagicMock(return_value=None))
def test_arches_nightlies_mismatchs(self):
"""
The command expects one nightly/standard for each group arch,
and should raise an error otherwise
"""

# 2 group arches, 1 nightly
gacli = flexmock(GenAssemblyCli(
runtime=MagicMock(assembly='stream', arches=['amd64', 's390x']),
nightlies=['4.13.0-0.nightly-2022-12-01-153811']
Expand All @@ -56,6 +81,11 @@ def test_arches_nightlies_mismatchs(self):

@patch('doozerlib.cli.release_gen_assembly.GenAssemblyCli._exit_with_error', MagicMock(return_value=None))
def test_previous_and_auto_previous(self):
"""
Only one among `--previous` and `--auto-previous` can be used.
The command should raise an error otherwise
"""

gacli = flexmock(GenAssemblyCli(
runtime=MagicMock(assembly='stream', arches=['amd64']),
nightlies=['4.13.0-0.nightly-2022-12-01-153811'],
Expand All @@ -67,6 +97,12 @@ def test_previous_and_auto_previous(self):

@patch('doozerlib.cli.release_gen_assembly.GenAssemblyCli._exit_with_error', MagicMock(return_value=None))
def test_custom_assembly(self):
"""
Custom releases don't have previous list. The command should raise an error if `custom` is true,
but one among `auto_previous`, `previous_list` or `in_flight` is specified
"""

# Custom and auto_previous
gacli = flexmock(GenAssemblyCli(
runtime=MagicMock(assembly='stream', arches=['amd64']),
nightlies=['4.13.0-0.nightly-2022-12-01-153811'],
Expand All @@ -76,6 +112,7 @@ def test_custom_assembly(self):
gacli.should_receive('_exit_with_error').once()
gacli._validate_params()

# Custom and previous_list
gacli = flexmock(GenAssemblyCli(
runtime=MagicMock(assembly='stream', arches=['amd64']),
nightlies=['4.13.0-0.nightly-2022-12-01-153811'],
Expand All @@ -85,6 +122,7 @@ def test_custom_assembly(self):
gacli.should_receive('_exit_with_error').once()
gacli._validate_params()

# Custom and in_flight
gacli = flexmock(GenAssemblyCli(
runtime=MagicMock(assembly='stream', arches=['amd64']),
nightlies=['4.13.0-0.nightly-2022-12-01-153811'],
Expand All @@ -96,6 +134,11 @@ def test_custom_assembly(self):

@patch('doozerlib.cli.release_gen_assembly.GenAssemblyCli._exit_with_error', MagicMock(return_value=None))
def test_group_nightly_mismatch(self):
"""
Specified nightlies must match the group `major.minor` parameter.
The command should raise an error otherwise
"""

runtime = MagicMock()
runtime.get_minor_version.return_value = '4.12'
gacli = flexmock(GenAssemblyCli(
Expand All @@ -106,8 +149,15 @@ def test_group_nightly_mismatch(self):
gacli._get_release_pullspecs()

def test_nightly_release_pullspecs(self):
"""
Check that for nightlies matching group param, two maps are populated:
One that associates the group arch with the complete nightlies pullspecs,
and one that associates the group arch with the nightlies names
"""

runtime = MagicMock()
runtime.get_minor_version.return_value = '4.13'

gacli = GenAssemblyCli(
runtime=runtime,
nightlies=['4.13.0-0.nightly-2022-12-01-153811'],
Expand All @@ -118,13 +168,40 @@ def test_nightly_release_pullspecs(self):
{'x86_64': 'registry.ci.openshift.org/ocp/release:4.13.0-0.nightly-2022-12-01-153811'}
)
self.assertEqual(
gacli.reference_releases_by_arch['x86_64'],
'4.13.0-0.nightly-2022-12-01-153811'
gacli.reference_releases_by_arch,
{'x86_64': '4.13.0-0.nightly-2022-12-01-153811'}
)

gacli = GenAssemblyCli(
runtime=runtime,
nightlies=['4.13.0-0.nightly-2022-12-01-153811', '4.13.0-0.nightly-arm64-2022-12-05-151453'],
)
gacli._get_release_pullspecs()
self.assertEqual(
gacli.release_pullspecs,
{
'x86_64': 'registry.ci.openshift.org/ocp/release:4.13.0-0.nightly-2022-12-01-153811',
'aarch64': 'registry.ci.openshift.org/ocp-arm64/release-arm64:4.13.0-0.nightly-arm64-2022-12-05-151453'
}
)
self.assertEqual(
gacli.reference_releases_by_arch,
{
'x86_64': '4.13.0-0.nightly-2022-12-01-153811',
'aarch64': '4.13.0-0.nightly-arm64-2022-12-05-151453'
}
)

def test_multi_nighly_arch(self):
"""
Only one nightly per group arch should be specified.
The command should raise an error otherwise
"""

runtime = MagicMock()
runtime.get_minor_version.return_value = '4.13'

# 2 nightlies for x86_64
gacli = GenAssemblyCli(
runtime=runtime,
nightlies=[
Expand All @@ -137,6 +214,11 @@ def test_multi_nighly_arch(self):

@patch('doozerlib.cli.release_gen_assembly.GenAssemblyCli._exit_with_error', MagicMock(return_value=None))
def test_group_standard_mismatch(self):
"""
Specified standard releases must match the group `major.minor` parameter.
The command should raise an error otherwise
"""

runtime = MagicMock()
runtime.get_minor_version.return_value = '4.12'
gacli = flexmock(GenAssemblyCli(
Expand All @@ -147,6 +229,12 @@ def test_group_standard_mismatch(self):
gacli._get_release_pullspecs()

def test_standard_release_pullspecs(self):
"""
Check that for standard releases matching group param, only one map is populated:
the one that associates the group arch with the releases pullspecs.
The one that associates the group arch with the nightlies names should be left empty
"""

runtime = MagicMock()
runtime.get_minor_version.return_value = '4.11'
gacli = GenAssemblyCli(
Expand All @@ -164,6 +252,11 @@ def test_standard_release_pullspecs(self):
)

def test_multi_standard_arch(self):
"""
Only one standard release per group arch should be specified.
The command should raise an error otherwise
"""

runtime = MagicMock()
runtime.get_minor_version.return_value = '4.11'
gacli = GenAssemblyCli(
Expand Down

0 comments on commit 8b52cab

Please sign in to comment.