|
1 | 1 | """Which default-branch and head-scan parameters a full scan is created with.""" |
2 | 2 |
|
3 | 3 | import pytest |
| 4 | +from git import Repo |
4 | 5 |
|
5 | 6 | from socketsecurity import socketcli |
6 | 7 | from socketsecurity.core import Core |
@@ -127,6 +128,39 @@ def test_scm_detection_still_marks_the_default_branch_run( |
127 | 128 | assert params.commit_message.strip() == "dev work" |
128 | 129 |
|
129 | 130 |
|
| 131 | +@pytest.mark.parametrize("branch", ["refs/heads/develop", "origin/develop", "refs/remotes/origin/develop"]) |
| 132 | +def test_qualified_default_branch_uses_the_short_branch_name( |
| 133 | + cli_runtime, github_dispatch_on_develop, branch # noqa: F811 |
| 134 | +): |
| 135 | + assert github_dispatch_on_develop(["--branch", branch]) == 0 |
| 136 | + |
| 137 | + params = _scan_params(cli_runtime) |
| 138 | + assert params.branch == "develop" |
| 139 | + assert _flags(params) == (True, True) |
| 140 | + |
| 141 | + |
| 142 | +def test_qualified_scan_of_another_branch_does_not_mark_it_as_default( |
| 143 | + cli_runtime, github_dispatch_on_develop # noqa: F811 |
| 144 | +): |
| 145 | + assert github_dispatch_on_develop(["--branch", "refs/heads/main"]) == 0 |
| 146 | + |
| 147 | + params = _scan_params(cli_runtime) |
| 148 | + assert params.branch == "main" |
| 149 | + assert params.make_default_branch is False |
| 150 | + |
| 151 | + |
| 152 | +def test_branch_named_like_a_remote_shorthand_keeps_its_name( |
| 153 | + cli_runtime, github_dispatch_on_develop, release_tag_checkout # noqa: F811 |
| 154 | +): |
| 155 | + Repo(release_tag_checkout.path).create_head("origin/develop") |
| 156 | + |
| 157 | + assert github_dispatch_on_develop(["--branch", "origin/develop"]) == 0 |
| 158 | + |
| 159 | + params = _scan_params(cli_runtime) |
| 160 | + assert params.branch == "origin/develop" |
| 161 | + assert params.make_default_branch is False |
| 162 | + |
| 163 | + |
130 | 164 | def test_explicit_default_branch_overrides_the_explicit_ref_check( |
131 | 165 | cli_runtime, github_dispatch_on_develop, release_tag_checkout # noqa: F811 |
132 | 166 | ): |
|
0 commit comments