Skip to content

Commit 828f798

Browse files
committed
update tests to check for missing data issues
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent ee8e36a commit 828f798

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

tests/unit/test_output.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ def test_sbom_file_saving(self, handler, tmp_path):
123123
handler.save_sbom_file(diff, str(sbom_path))
124124
assert sbom_path.exists()
125125

126+
def test_sbom_file_saving_without_sbom_writes_empty_array(self, handler, tmp_path):
127+
diff = Diff()
128+
sbom_path = tmp_path / "empty.json"
129+
handler.save_sbom_file(diff, str(sbom_path))
130+
assert sbom_path.exists()
131+
assert json.loads(sbom_path.read_text()) == []
132+
126133
def test_json_file_saving(self, tmp_path):
127134
from socketsecurity.config import CliConfig
128135
from unittest.mock import Mock

tests/unit/test_socketcli.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from socketsecurity.core.classes import Diff, Package
2+
from socketsecurity.socketcli import build_license_artifact_payload
3+
4+
5+
def test_build_license_artifact_payload_without_packages_returns_empty_dict():
6+
diff = Diff()
7+
8+
payload = build_license_artifact_payload(diff)
9+
10+
assert payload == {}
11+
12+
13+
def test_build_license_artifact_payload_serializes_package_fields():
14+
diff = Diff()
15+
diff.packages = {
16+
"pypi/requests@2.31.0": Package(
17+
id="pkg-1",
18+
name="requests",
19+
version="2.31.0",
20+
type="pypi",
21+
score={},
22+
alerts=[],
23+
direct=True,
24+
url="https://socket.dev/pypi/package/requests/overview/2.31.0",
25+
license="Apache-2.0",
26+
licenseDetails=[{"id": "Apache-2.0"}],
27+
licenseAttrib=[{"id": "Apache-2.0"}],
28+
purl="requests@2.31.0",
29+
)
30+
}
31+
32+
payload = build_license_artifact_payload(diff)
33+
34+
assert payload == {
35+
"pkg-1": {
36+
"id": "pkg-1",
37+
"name": "requests",
38+
"version": "2.31.0",
39+
"ecosystem": "pypi",
40+
"direct": True,
41+
"url": "https://socket.dev/pypi/package/requests/overview/2.31.0",
42+
"license": "Apache-2.0",
43+
"licenseDetails": [{"id": "Apache-2.0"}],
44+
"licenseAttrib": [{"id": "Apache-2.0"}],
45+
"purl": "requests@2.31.0",
46+
}
47+
}

0 commit comments

Comments
 (0)