Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit with error when specified target is not found in source deps #6

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading