Skip to content

Commit

Permalink
exit with error when specified target is not found in source deps
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-es committed Apr 4, 2024
1 parent d4c8cad commit 460a257
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bazel2snyk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ def main(

bazel2snyk.bazel_to_depgraph(parent_node_id=bazel_target, depth=0)

if len(bazel2snyk.dep_graph.graph()["depGraph"]["graph"]["nodes"]) <= 1:
logger.error(
f"No {package_source} dependencies found for given target, please verify --bazel-target exists in the source data"
)
sys.exit(2)

if prune_all:
logger.info("Pruning graph ...")
time.sleep(2)
Expand Down
14 changes: 14 additions & 0 deletions bazel2snyk/test/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
"abcdefg",
]

pip_args["bad_target"] = [
# "--debug",
"--print-deps",
"--package-source",
"pip",
"--bazel-deps-xml",
f"{pip_fixtures['pip']}",
"--bazel-target",
"//snyk/cli:main",
"print-graph",
"--snyk-org-id",
"abcdefg",
]

pip_args["print_graph"] = [
# "--debug",
"--print-deps",
Expand Down
9 changes: 9 additions & 0 deletions bazel2snyk/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def test_bad_args():
assert result.exit_code == 2


def test_bad_target():
"""
Test for target not found in source
"""
result = runner.invoke(cli, pip_args["bad_target"])
assert result.exit_code == 2


def test_pip_command_print_graph():
"""
Test for printing the dep graph
Expand Down

0 comments on commit 460a257

Please sign in to comment.