From eafa4a4069b4ce243b9d66b04540ff57342c5c9f Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Thu, 11 May 2023 10:03:09 +0200 Subject: [PATCH] first try to implement get_version --- .../python/ddadevops/domain/build_file.py | 5 +++++ src/test/python/domain/test_build_file.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/python/ddadevops/domain/build_file.py b/src/main/python/ddadevops/domain/build_file.py index 2e70893..285c6d1 100644 --- a/src/main/python/ddadevops/domain/build_file.py +++ b/src/main/python/ddadevops/domain/build_file.py @@ -1,6 +1,7 @@ from enum import Enum from typing import Optional from pathlib import Path +import json from .common import ( Validateable, Devops, @@ -45,3 +46,7 @@ class BuildFile(Validateable): case _: result = None return result + + def get_version(self) -> Version: + version = json.loads(self.content)["version"] + return Version.from_str(version) diff --git a/src/test/python/domain/test_build_file.py b/src/test/python/domain/test_build_file.py index c505438..833f0c6 100644 --- a/src/test/python/domain/test_build_file.py +++ b/src/test/python/domain/test_build_file.py @@ -2,6 +2,7 @@ from pathlib import Path from src.main.python.ddadevops.domain import ( BuildFileType, BuildFile, + Version, ) @@ -31,3 +32,21 @@ def test_sould_calculate_build_type(): "content" ) assert sut.build_file_type() == BuildFileType.JAVA_CLOJURE + +def test_sould_parse_version(): + sut = BuildFile( + Path("./package.js"), + """{ + "name": "c4k-jira", + "description": "Generate c4k yaml for a jira deployment.", + "author": "meissa GmbH", + "version": "1.1.5-SNAPSHOT", + "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jira#readme", + "bin": { + "c4k-jira": "./c4k-jira.js" + }, +} +""" + ) + assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT") +