From 2e2c04c8ba163b355c5d1c7fd8b0f80e79cf994b Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Wed, 10 May 2023 19:37:15 +0200 Subject: [PATCH] finish version --- doc/architecture/Domain.md | 4 +-- src/main/python/ddadevops/domain/version.py | 19 ++++++++++++ src/test/python/domain/test_version.py | 33 ++++++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/doc/architecture/Domain.md b/doc/architecture/Domain.md index bce25f8..3c9014b 100644 --- a/doc/architecture/Domain.md +++ b/doc/architecture/Domain.md @@ -51,8 +51,8 @@ classDiagram get_version_string() create_major() create_minor() - create_patchn() - create_bump() + create_patch() + create_bump(snapshot_suffix) } Devops *-- "0..1" Image: spcialized_builds diff --git a/src/main/python/ddadevops/domain/version.py b/src/main/python/ddadevops/domain/version.py index 94b07be..1b01b29 100644 --- a/src/main/python/ddadevops/domain/version.py +++ b/src/main/python/ddadevops/domain/version.py @@ -50,6 +50,15 @@ class Version(Validateable): result += [f"version_string not parsed correct. Input was {self.version_string} parsed was {self.to_string()}"] return result + def create_bump(self, snapshot_suffix: str = None): + new_version_list = self.version_list.copy() + if self.is_snapshot(): + return Version(new_version_list, snapshot_suffix=self.snapshot_suffix, version_str=None) + else: + new_version_list[2] = 0 + new_version_list[1] += 1 + return Version(new_version_list, snapshot_suffix=snapshot_suffix, version_str=None) + def create_patch(self): new_version_list = self.version_list.copy() if self.is_snapshot(): @@ -66,3 +75,13 @@ class Version(Validateable): new_version_list[2] = 0 new_version_list[1] += 1 return Version(new_version_list, snapshot_suffix=None, version_str=None) + + def create_major(self): + new_version_list = self.version_list.copy() + if self.is_snapshot() and new_version_list[2] == 0 and new_version_list[1] == 0 : + return Version(new_version_list, snapshot_suffix=None, version_str=None) + else: + new_version_list[2] = 0 + new_version_list[1] = 0 + new_version_list[0] += 1 + return Version(new_version_list, snapshot_suffix=None, version_str=None) diff --git a/src/test/python/domain/test_version.py b/src/test/python/domain/test_version.py index c13e277..2caee0d 100644 --- a/src/test/python/domain/test_version.py +++ b/src/test/python/domain/test_version.py @@ -78,4 +78,35 @@ def test_should_create_minor(): version = Version.from_str("1.3.0") sut = version.create_minor() - assert sut.to_string() == "1.4.0" \ No newline at end of file + assert sut.to_string() == "1.4.0" + + +def test_should_create_major(): + version = Version.from_str("1.2.3-SNAPSHOT") + sut = version.create_major() + assert sut.to_string() == "2.0.0" + + version = Version.from_str("1.2.3") + sut = version.create_major() + assert sut.to_string() == "2.0.0" + + version = Version.from_str("1.0.0-SNAPSHOT") + sut = version.create_major() + assert sut.to_string() == "1.0.0" + + version = Version.from_str("1.0.0") + sut = version.create_major() + assert sut.to_string() == "2.0.0" + +def test_should_create_bump(): + version = Version.from_str("1.2.3-SNAPSHOT") + sut = version.create_bump() + assert sut.to_string() == "1.2.3-SNAPSHOT" + + version = Version.from_str("1.2.3") + sut = version.create_bump("SNAPSHOT") + assert sut.to_string() == "1.3.0-SNAPSHOT" + + version = Version.from_str("1.0.0") + sut = version.create_bump("SNAPSHOT") + assert sut.to_string() == "1.1.0-SNAPSHOT" \ No newline at end of file