Skip to content

Commit 3fbbc05

Browse files
Fix catalog patch test
1 parent 0f80094 commit 3fbbc05

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

cortexapps_cli/commands/catalog.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ class CatalogCommandOptions:
5050
]
5151
append_arrays = Annotated[
5252
Optional[bool],
53-
typer.Option("--append-arrays", "-aa", help="Default merge behavior is to replace arrays, set this to true to append arrays instead. For simple types, duplicate values will be removed from the merged array", show_default=False)
53+
typer.Option("--append-arrays", "-a", help="Default merge behavior is to replace arrays, set this to true to append arrays instead. For simple types, duplicate values will be removed from the merged array", show_default=False)
54+
]
55+
fail_if_not_exist = Annotated[
56+
Optional[bool],
57+
typer.Option("--fail-if-not-exist", "-n", help="Default behavior is to upsert the entity, if set command will fail (404) if the entity specified in x-cortex-tag does not exist.", show_default=False)
5458
]
5559
git_repositories = Annotated[
5660
Optional[str],
@@ -292,6 +296,7 @@ def patch(
292296
delete_marker_value = typer.Option("__delete__", "--delete-marker-value", "-dmv", help="Delete keys with this value from the merged yaml, defaults to __delete__, if any values match this, they will not be included in merged YAML. For example my_value: __delete__ will remove my_value from the merged YAML."),
293297
dry_run: CatalogCommandOptions.dry_run = False,
294298
append_arrays: CatalogCommandOptions.append_arrays = False,
299+
fail_if_not_exist: CatalogCommandOptions.fail_if_not_exist = False,
295300
):
296301
"""
297302
Creates or updates an entity. If the YAML refers to an entity that already exists (as referenced by the x-cortex-tag), this API will merge the specified changes into the existing entity
@@ -301,7 +306,8 @@ def patch(
301306
params = {
302307
"dryRun":dry_run,
303308
"appendArrays": append_arrays,
304-
"deleteMarkerValue": delete_marker_value
309+
"deleteMarkerValue": delete_marker_value,
310+
"failIfEntityDoesNotExist": fail_if_not_exist
305311
}
306312

307313
r = client.patch("api/v1/open-api", data=file_input.read(), params=params, content_type="application/openapi;charset=UTF-8")
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
openapi: 3.0.0
22
info:
3-
title: Patch Entity
3+
title: CLI Test Patch Entity
44
description: Entity that will be created to test catalog patch entity
5-
x-cortex-tag: patch-entity
6-
x-cortex-type: component
5+
x-cortex-tag: cli-test-patch-entity
6+
x-cortex-type: service
77
x-cortex-groups:
8-
- public-api-test
9-
x-cortex-definition: {}
8+
- cli-test
109
x-cortex-custom-metadata:
1110
owners:
1211
- owner-1

data/run-time/patch-entity.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
openapi: 3.0.0
22
info:
3-
x-cortex-tag: patch-entity
3+
x-cortex-tag: cli-test-patch-entity
44
x-cortex-custom-metadata:
55
owners:
66
- owner-2

tests/test_catalog_patch_entity.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
from common import *
1+
from tests.helpers.utils import *
22

33
def test(capsys):
4-
cli(["-q", "catalog", "patch", "-f", "data/run-time/create-patch-entity.yaml"])
5-
# Need to clear captured system output from the above commands to clear the way for the next one.
6-
capsys.readouterr()
4+
cli(["catalog", "patch", "-a", "-f", "data/run-time/patch-entity.yaml"])
75

8-
response = cli_command(capsys, ["catalog", "descriptor", "-t", "patch-entity"])
9-
assert response['info']['x-cortex-tag'] == "patch-entity"
10-
11-
# Need to clear captured system output from the above commands to clear the way for the next one.
12-
capsys.readouterr()
13-
14-
cli(["-q", "catalog", "patch", "-a", "-f", "data/run-time/patch-entity.yaml"])
15-
capsys.readouterr()
16-
17-
response = cli_command(capsys, ["custom-data", "get", "-t", "patch-entity", "-k", "owners"])
6+
response = cli(["custom-data", "get", "-t", "cli-test-patch-entity", "-k", "owners"])
187
assert 'owner-2' in response['value'], "owner-2 should have been merged in owners array"

0 commit comments

Comments
 (0)