Skip to content

Commit

Permalink
Merge pull request #22 from abrugaro/add-dotnet-analysis-test
Browse files Browse the repository at this point in the history
[RFR] Add hello-world dotnet analysis test
  • Loading branch information
sshveta authored Aug 2, 2024
2 parents 69bbc31 + f0236ad commit 0bffb9a
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 0 deletions.
Binary file added data/applications/dotnet-hello-world.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions data/dotnet_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hello_world": {
"app_name": "dotnet-hello-world",
"file_name": "dotnet-hello-world.zip"
}
}
14 changes: 14 additions & 0 deletions data/yaml/dotnet/example_rules/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- category: mandatory
customVariables: []
description: MVC Method names have changed from .NET Framework
effort: 1
labels:
- konveyor.io/source=dotnetframework
message: |-
HttpNotFound was replaced with NotFound in .NET Core
ruleID: removed-dotnet-framework-00000
when:
or:
- dotnet.referenced:
pattern: "HttpNotFound"
namespace: "System.Web.Mvc"
3 changes: 3 additions & 0 deletions data/yaml/dotnet/example_rules/ruleset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: dotnet8/dotnetframework45
description: This ruleset provides analysis with respect to API changes between
.NET Framework 4.5 and .NET 8.
7 changes: 7 additions & 0 deletions fixtures/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ def analysis_data():
with open('data/analysis.json', 'r') as file:
json_list = json.load(file)
return json_list


@pytest.fixture(scope="session")
def dotnet_analysis_data():
with open('data/dotnet_analysis.json', 'r') as file:
json_list = json.load(file)
return json_list
Empty file added tests/analysis/__init__.py
Empty file.
Empty file.
33 changes: 33 additions & 0 deletions tests/analysis/dotnet/test_dotnet_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import subprocess

from utils import constants
from utils.command import build_analysis_command
from utils.common import extract_zip_to_temp_dir


# Polarion TC MTA-568
def test_hello_world_analysis_with_rules(dotnet_analysis_data):
# Avoid running this test on Windows
if os.name == 'nt':
return

application_data = dotnet_analysis_data["hello_world"]
application_path = os.path.join(
os.getenv(constants.PROJECT_PATH),
'data/applications',
application_data['file_name']
)
custom_rules_path = os.path.join(os.getenv(constants.PROJECT_PATH), 'data/yaml/dotnet/example_rules')

with extract_zip_to_temp_dir(application_path) as tempdir:
command = build_analysis_command(
tempdir,
"",
"",
**{'rules': custom_rules_path}
)

output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout

assert 'Static report created' in output
Empty file added tests/analysis/java/__init__.py
Empty file.
File renamed without changes.
26 changes: 26 additions & 0 deletions utils/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import tempfile
import zipfile
from contextlib import contextmanager

from utils import constants


@contextmanager
def extract_zip_to_temp_dir(application_path):
"""
Creates a temporary directory and extracts a zip file to it.
:param application_path: Path to the zip file
:yield: path to the extracted zip file
"""

tempdir = tempfile.TemporaryDirectory(dir=os.getenv(constants.PROJECT_PATH))

# Adjusts the permissions to allow access to subprocesses
os.chmod(tempdir.name, 0o777)

with zipfile.ZipFile(application_path, 'r') as zip_ref:
zip_ref.extractall(tempdir.name)

yield tempdir.name

0 comments on commit 0bffb9a

Please sign in to comment.