Skip to content

Commit

Permalink
[RFR] [TA] Add nodejs provider analysis test (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrugaro authored Sep 13, 2024
1 parent b7d3a5c commit ca70ca4
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 1 deletion.
5 changes: 5 additions & 0 deletions data/applications/nodejs_app/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function testFunction() {
return "Hello, world!";
}

testFunction();
8 changes: 8 additions & 0 deletions data/nodejs_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"nodejs_app_project": {
"app_name": "nodejs_app",
"file_name": "nodejs_app",
"target": "quarkus",
"source": ""
}
}
22 changes: 22 additions & 0 deletions data/yaml/python_rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

- message: python sample rule 001
ruleID: python-sample-rule-001
description: sample-rule-1 - this should appear as an issue
effort: 1
when:
python.referenced:
pattern: "hello_world"
- message: python sample rule 002
ruleID: python-sample-rule-002
description: sample-rule-2 - this should appear as an issue
effort: 5
when:
python.referenced:
pattern: "speak"
- message: python sample rule 003
ruleID: python-sample-rule-003
description: sample-rule-3 - this should appear as an insight
when:
python.referenced:
pattern: "create_custom_resource_definition"

7 changes: 6 additions & 1 deletion fixtures/analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import pytest


@pytest.fixture(scope="session")
def analysis_data():
with open('data/analysis.json', 'r') as file:
Expand All @@ -20,3 +19,9 @@ def golang_analysis_data():
with open('data/golang_analysis.json', 'r') as file:
json_list = json.load(file)
return json_list

@pytest.fixture(scope="session")
def nodejs_analysis_data():
with open('data/nodejs.json', 'r') as file:
json_list = json.load(file)
return json_list
Empty file.
23 changes: 23 additions & 0 deletions tests/analysis/generic/test_nodejs_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import subprocess

from utils import constants
from utils.command import build_analysis_command
from utils.report import get_json_from_report_output_file


# Polarion TC MTA-542
def test_nodejs_provider_analysis(nodejs_analysis_data):
application_data = nodejs_analysis_data['nodejs_app_project']
custom_rules_path = os.path.join(os.getenv(constants.PROJECT_PATH), 'data/yaml', 'python_rules.yaml')
command = build_analysis_command(
application_data['file_name'],
application_data['source'],
application_data['target'],
**{'rules': custom_rules_path,
'provider': "nodejs"}
)

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

assert 'Static report created' in output
Empty file.
23 changes: 23 additions & 0 deletions tests/analysis/nodejs/test_nodejs_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import subprocess

from utils import constants
from utils.command import build_analysis_command


# Polarion TC MTA-542
def test_nodejs_provider_analysis(nodejs_analysis_data):
application_data = nodejs_analysis_data['nodejs_app_project']
# TODO: replace with a nodejs rule when available and validate them
custom_rules_path = os.path.join(os.getenv(constants.PROJECT_PATH), 'data/yaml', 'python_rules.yaml')
command = build_analysis_command(
application_data['file_name'],
application_data['source'],
application_data['target'],
**{'rules': custom_rules_path,
'provider': "nodejs"}
)

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

assert 'Static report created' in output

0 comments on commit ca70ca4

Please sign in to comment.