summaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-10-05 07:43:14 -0700
committerNejc Habjan <hab.nejc@gmail.com>2022-10-06 09:24:02 +0200
commit9b88132078ed37417c2a45369b4976c9c67f7882 (patch)
tree61f075c8d2685df36153970f2a93937ac9f14c86 /tests/functional
parentc15bd33f45fbd9d064f1e173c6b3ca1b216def2f (diff)
downloadgitlab-9b88132078ed37417c2a45369b4976c9c67f7882.tar.gz
fix(cli): handle list response for json/yaml output
Handle the case with the CLI where a list response is returned from GitLab and json/yaml output is requested. Add a functional CLI test to validate it works. Closes: #2287
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/cli/test_cli_repository.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/functional/cli/test_cli_repository.py b/tests/functional/cli/test_cli_repository.py
index 7f521b4..90adc5e 100644
--- a/tests/functional/cli/test_cli_repository.py
+++ b/tests/functional/cli/test_cli_repository.py
@@ -1,3 +1,7 @@
+import json
+import time
+
+
def test_project_create_file(gitlab_cli, project):
file_path = "README"
branch = "main"
@@ -45,6 +49,46 @@ def test_list_all_commits(gitlab_cli, project):
assert len(ret_all.stdout) > len(ret.stdout)
+def test_commit_merge_requests(gitlab_cli, project, merge_request, wait_for_sidekiq):
+ """This tests the `project-commit merge-requests` command and also tests
+ that we can print the result using the `json` formatter"""
+ # create and then merge a merge-request
+ mr = merge_request(source_branch="test_commit_merge_requests")
+ merge_result = mr.merge(should_remove_source_branch=True)
+ wait_for_sidekiq(timeout=60)
+ # Wait until it is merged
+ mr_iid = mr.iid
+ for _ in range(60):
+ mr = project.mergerequests.get(mr_iid)
+ if mr.merged_at is not None:
+ break
+ time.sleep(0.5)
+ assert mr.merged_at is not None
+ time.sleep(0.5)
+ wait_for_sidekiq(timeout=60)
+
+ commit_sha = merge_result["sha"]
+ cmd = [
+ "-o",
+ "json",
+ "project-commit",
+ "merge-requests",
+ "--project-id",
+ project.id,
+ "--id",
+ commit_sha,
+ ]
+ ret = gitlab_cli(cmd)
+ assert ret.success
+
+ json_list = json.loads(ret.stdout)
+ assert isinstance(json_list, list)
+ assert len(json_list) == 1
+ mr_dict = json_list[0]
+ assert mr_dict["id"] == mr.id
+ assert mr_dict["iid"] == mr.iid
+
+
def test_revert_commit(gitlab_cli, project):
commit = project.commits.list()[0]