|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | + |
| 4 | + |
| 5 | +def run_command(command): # 리눅스 명령어 실행 |
| 6 | + result = subprocess.run(command, shell=True, capture_output=True, text=True) |
| 7 | + success = result.returncode == 0 |
| 8 | + output = result.stdout if success else result.stderr |
| 9 | + return success, output |
| 10 | + |
| 11 | + |
| 12 | +def test_test_run_environment(): # 테스트 환경 tox.ini |
| 13 | + # Given |
| 14 | + run_command("rm -rf test_result") |
| 15 | + os.makedirs("test_result", exist_ok=True) |
| 16 | + |
| 17 | + # When |
| 18 | + csv_success, _ = run_command("fosslight_bin -p . -o test_result -f csv") |
| 19 | + exclude_success, _ = run_command("fosslight_bin -p . -e test commons-logging-1.2.jar -o test_result/exclude_result.csv -f csv") |
| 20 | + files_in_result = run_command("ls test_result/")[1].split() |
| 21 | + txt_success, txt_output = run_command("bash -c 'find test_result -type f -name \"fosslight_log*.txt\"'") |
| 22 | + |
| 23 | + # Then |
| 24 | + csv_files = [f for f in files_in_result if f.endswith('.csv')] |
| 25 | + txt_files = txt_output.split() |
| 26 | + assert csv_success is True, "Test Run Environment: CSV files not properly created (not create)" |
| 27 | + assert len(csv_files) > 0, "Test Run Environment: CSV files not properly created (length)" |
| 28 | + assert exclude_success is True, "Test Run Environment: Exclude feature fail" |
| 29 | + assert len(txt_files) > 0, "Test Run Environment: txt files not properly created" |
| 30 | + |
| 31 | + |
| 32 | +def test_release_environment(): # 릴리즈 환경 tox.ini |
| 33 | + # Given |
| 34 | + run_command("rm -rf test_result") |
| 35 | + os.makedirs("test_result", exist_ok=True) |
| 36 | + |
| 37 | + # When |
| 38 | + help_success, _ = run_command("fosslight_bin -h") |
| 39 | + csv_success, _ = run_command("fosslight_bin -p . -o test_result/result.csv -f csv") |
| 40 | + exclude_csv_success, _ = run_command("fosslight_bin -p . -e test commons-logging-1.2.jar -o test_result/exclude_result.csv -f csv") |
| 41 | + json_success, _ = run_command("fosslight_bin -p . -o test_result/result.json -f opossum") |
| 42 | + files_in_result = run_command("ls test_result/")[1].split() |
| 43 | + |
| 44 | + # Then |
| 45 | + required_files = ['result.csv', 'exclude_result.csv', 'result.json'] |
| 46 | + files_exist = all(f in files_in_result for f in required_files) |
| 47 | + assert help_success is True, "Release Run Environment: help method not properly processing" |
| 48 | + assert csv_success is True, "Release Run Environment: CSV files not properly created" |
| 49 | + assert exclude_csv_success is True, "Release Run Environment: Exclude feature fail" |
| 50 | + assert json_success is True, "Release Run Environment: json files not properly created" |
| 51 | + assert files_exist is True, "Release Run Environment: Required files not properly created" |
0 commit comments