From d144b8cc14b7c3ce27ca9c5f401a6dfff79d99f3 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Thu, 11 Jun 2026 14:12:00 +0200 Subject: [PATCH 1/5] Create tests for stream commands --- tests/integration/streams/test_streams.py | 186 ++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 tests/integration/streams/test_streams.py diff --git a/tests/integration/streams/test_streams.py b/tests/integration/streams/test_streams.py new file mode 100644 index 000000000..319f4e922 --- /dev/null +++ b/tests/integration/streams/test_streams.py @@ -0,0 +1,186 @@ +from linodecli.exit_codes import ExitCodes +from tests.integration.helpers import ( + BASE_CMDS, + assert_headers_in_lines, + assert_help_actions_list, + exec_failing_test_command, + exec_test_command, + get_random_text, +) +from tests.integration.streams.fixtures import ( + create_destination_akamai_object_storage_type, +) + + +def test_help_streams(): + output = exec_test_command( + BASE_CMDS["streams"] + ["--help", "--text", "--delimiter=,"] + ) + actions = [ + "create", + "delete", + "destination-create", + "destination-delete", + "destination-history-view", + "destination-update", + "destination-view", + "destinations-list", + "history-view", + "ls, list", + "update", + "view", + ] + assert_help_actions_list(actions, output) + + +def test_list_destinations(create_destination_akamai_object_storage_type): + result = exec_test_command( + BASE_CMDS["streams"] + ["destinations-list", "--delimiter", ",", "--text"] + ) + lines = result.splitlines() + headers = [ + "created", + "created_by", + "details", + "id", + "label", + "status", + "type", + "updated", + "updated_by", + "version", + ] + assert_headers_in_lines(headers, lines) + + +def test_create_destination_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "destination-create", + "--label", + "test", + "--type", + "custom_https", + "--details", + "test", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 400" in result + assert "details,Must be of type Object" in result + + +def test_create_view_update_remove_destination(): + label = get_random_text(8) + "_destination_cli_test" + result_create_stream = exec_test_command( + BASE_CMDS["streams"] + + [ + "destination-create", + "--details", + "--label", + label, + "--type", + "--delimiter", + ",", + "--text", + ] + ).splitlines() + headers = [ + "created", + "created_by", + "details", + "id", + "label", + "status", + "type", + "updated", + "updated_by", + "version", + ] + assert_headers_in_lines(headers, result_create_stream) + assert label in result_create_stream[1] + + result_view = exec_test_command( + BASE_CMDS["streams"] + + ["destination-view", result_create_stream[0], "--delimiter", ",", "--text"] + ).splitlines() + assert_headers_in_lines(headers, result_view) + assert label in result_view[1] + + result_update_stream = exec_test_command( + BASE_CMDS["streams"] + + [ + "destination-update", + result_create_stream[0], + "--delimiter", + ",", + "--text", + ] + ).splitlines() + assert_headers_in_lines(headers, result_update_stream) + + exec_test_command( + BASE_CMDS["streams"] + + [ + "destination-delete", + result_create_stream[0], + "--delimiter", + ",", + "--text", + ] + ).splitlines() + + exec_test_command( + BASE_CMDS["streams"] + + ["destination-view", result_create_stream[0], "--delimiter", ",", "--text"] + ) + + +def test_list_streams(): + result = exec_test_command( + BASE_CMDS["streams"] + ["list", "--delimiter", ",", "--text"] + ) + lines = result.splitlines() + headers = [ + "created", + "created_by", + "destinations.details.access_key_id", + "destinations.details.bucket_name", + "destinations.details.host", + "destinations.details.path", + "details.cluster_ids", + "details.is_auto_add_all_clusters_enabled", + "id", + "label", + "status", + "type", + "updated", + "updated_by", + "version", + ] + assert_headers_in_lines(headers, lines) + + +def test_create_stream_invalid_destination_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "create", + "--label", + "test", + "--type", + "audit_logs", + "--destinations", + "12341234", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 400" in result + assert "Destination not found" in result From 4ad3d102660414077344e2d828a5f34fec87f2e1 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Tue, 30 Jun 2026 15:59:35 +0200 Subject: [PATCH 2/5] Extends integration tests for streams commands --- tests/integration/helpers.py | 1 + tests/integration/streams/fixtures.py | 122 ++++++++++++++ tests/integration/streams/test_destination.py | 158 ++++++++++++++++++ tests/integration/streams/test_streams.py | 146 ++++++---------- 4 files changed, 329 insertions(+), 98 deletions(-) create mode 100644 tests/integration/streams/fixtures.py create mode 100644 tests/integration/streams/test_destination.py diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 84dbc1720..e20072c91 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -54,6 +54,7 @@ "regions", "ssh", "stackscripts", + "streams", "tickets", "tags", "users", diff --git a/tests/integration/streams/fixtures.py b/tests/integration/streams/fixtures.py new file mode 100644 index 000000000..66aa3e34d --- /dev/null +++ b/tests/integration/streams/fixtures.py @@ -0,0 +1,122 @@ +import os +from typing import Any, Dict + +import pytest +import requests + +from tests.integration.helpers import ( + BASE_CMDS, + delete_target_id, + exec_test_command, + get_random_region_with_caps, + get_random_text, +) + + +def get_object_storage_buckets() -> Dict[str, Any]: + token = os.getenv("LINODE_CLI_TOKEN") + if token is None: + raise ValueError("LINODE_CLI_TOKEN environment variable is not set. ") + host = os.getenv("LINODE_CLI_API_HOST") + if token is None: + raise ValueError( + "LINODE_CLI_API_HOST environment variable is not set. " + ) + version = os.getenv("LINODE_CLI_API_VERSION") + if token is None: + raise ValueError( + "LINODE_CLI_API_VERSION environment variable is not set. " + ) + + url = f"https://{host}/{version}/object-storage/buckets" + headers = { + "Authorization": f"Bearer {token}", + "Content-Type": "application/json", + } + + response = requests.get(url, headers=headers, timeout=30) + response.raise_for_status() + + return response.json() + + +@pytest.fixture(scope="session") +def create_stream(create_destination_akamai_object_storage_type): + label = get_random_text(8) + "_stream_cli_test" + result_create_stream = exec_test_command( + BASE_CMDS["streams"] + + [ + "create", + "--label", + label, + "--type", + "audit_logs", + "--destinations", + create_destination_akamai_object_storage_type[0], + "--delimiter", + ",", + "--text", + ] + ).splitlines() + yield result_create_stream + delete_target_id("streams", str(result_create_stream[1]), "delete") + + +@pytest.fixture +def create_object_storage_keys(): + label = get_random_text(8) + "_destination_cli_test" + test_bucket = get_object_storage_buckets()["data"][0] + result_keys = exec_test_command( + BASE_CMDS["object-storage"] + + [ + "keys-create", + "--label", + label, + "--bucket_access", + '[{"region": "' + + test_bucket["region"] + + '", "bucket_name": "' + + test_bucket["label"] + + '", "permissions": "read_write" }]', + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "access_key,id", + ] + ).split(",") + yield result_keys[0], test_bucket["label"], test_bucket["s3_endpoint"] + delete_target_id("object-storage", str(result_keys[1]), "keys-delete") + + +@pytest.fixture(scope="function") +def create_destination_akamai_object_storage_type(create_object_storage_keys): + get_random_region_with_caps(required_capabilities=["Linodes"]) + + label = get_random_text(8) + "_destination_cli_test" + result_create_destination = exec_test_command( + BASE_CMDS["streams"] + + [ + "destination-create", + "--label", + label, + "--type", + "akamai_object_storage", + "--details.host", + create_object_storage_keys[2], + "--details.bucket_name", + create_object_storage_keys[1], + "--details.path", + "audit-logs", + "--details.access_key_id", + create_object_storage_keys[0], + "--delimiter", + ",", + "--text", + ] + ).splitlines() + yield result_create_destination + delete_target_id( + "streams", str(result_create_destination[0]), "destination-delete" + ) diff --git a/tests/integration/streams/test_destination.py b/tests/integration/streams/test_destination.py new file mode 100644 index 000000000..a50156c0d --- /dev/null +++ b/tests/integration/streams/test_destination.py @@ -0,0 +1,158 @@ +from linodecli.exit_codes import ExitCodes +from tests.integration.helpers import ( + BASE_CMDS, + assert_headers_in_lines, + exec_failing_test_command, + exec_test_command, +) +from tests.integration.streams.fixtures import ( + create_destination_akamai_object_storage_type, + create_object_storage_keys, +) + + +def test_list_destinations(): + result = exec_test_command( + BASE_CMDS["streams"] + + ["destinations-list", "--delimiter", ",", "--text"] + ) + lines = result.splitlines() + headers = [ + "created", + "created_by", + "details", + "id", + "label", + "status", + "type", + "updated", + "updated_by", + "version", + ] + assert_headers_in_lines(headers, lines) + + +def test_create_destination_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "destination-create", + "--label", + "test", + "--type", + "custom_https", + "--details", + "test", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 400" in result + assert "details,Must be of type Object" in result + + +def test_view_destination_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "destination-view", + "1", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Destination not found" in result + + +def test_destination_history_view_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "destination-history-view", + "1", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Destination not found" in result + + +def test_update_destination_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "destination-update", + "1", + "--details", + "test", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Destination not found" in result + + +def test_remove_destination_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "destination-delete", + "1", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Destination not found" in result + + +def test_view_delete_destination(create_destination_akamai_object_storage_type): + result_view = exec_test_command( + BASE_CMDS["streams"] + + [ + "destination-view", + create_destination_akamai_object_storage_type, + "--delimiter", + ",", + "--text", + ], + ) + assert result_view == "test" + + exec_test_command( + BASE_CMDS["streams"] + + [ + "delete", + create_destination_akamai_object_storage_type, + "--delimiter", + ",", + "--text", + ], + ) + + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "destination-view", + create_destination_akamai_object_storage_type, + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Not found" in result diff --git a/tests/integration/streams/test_streams.py b/tests/integration/streams/test_streams.py index 319f4e922..dbeb1b0f5 100644 --- a/tests/integration/streams/test_streams.py +++ b/tests/integration/streams/test_streams.py @@ -5,10 +5,6 @@ assert_help_actions_list, exec_failing_test_command, exec_test_command, - get_random_text, -) -from tests.integration.streams.fixtures import ( - create_destination_akamai_object_storage_type, ) @@ -33,37 +29,17 @@ def test_help_streams(): assert_help_actions_list(actions, output) -def test_list_destinations(create_destination_akamai_object_storage_type): - result = exec_test_command( - BASE_CMDS["streams"] + ["destinations-list", "--delimiter", ",", "--text"] - ) - lines = result.splitlines() - headers = [ - "created", - "created_by", - "details", - "id", - "label", - "status", - "type", - "updated", - "updated_by", - "version", - ] - assert_headers_in_lines(headers, lines) - - -def test_create_destination_error(): +def test_create_stream_error(): result = exec_failing_test_command( BASE_CMDS["streams"] + [ - "destination-create", + "create", + "--destinations", + "1", "--label", "test", "--type", - "custom_https", - "--details", - "test", + "audit_logs", "--delimiter", ",", "--text", @@ -71,76 +47,42 @@ def test_create_destination_error(): expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 400" in result - assert "details,Must be of type Object" in result + assert "Destination not found" in result -def test_create_view_update_remove_destination(): - label = get_random_text(8) + "_destination_cli_test" - result_create_stream = exec_test_command( +def test_delete_stream_error(): + result = exec_failing_test_command( BASE_CMDS["streams"] + [ - "destination-create", - "--details", - "--label", - label, - "--type", + "delete", + "-2", "--delimiter", ",", "--text", - ] - ).splitlines() - headers = [ - "created", - "created_by", - "details", - "id", - "label", - "status", - "type", - "updated", - "updated_by", - "version", - ] - assert_headers_in_lines(headers, result_create_stream) - assert label in result_create_stream[1] + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Not found" in result - result_view = exec_test_command( - BASE_CMDS["streams"] - + ["destination-view", result_create_stream[0], "--delimiter", ",", "--text"] - ).splitlines() - assert_headers_in_lines(headers, result_view) - assert label in result_view[1] - result_update_stream = exec_test_command( - BASE_CMDS["streams"] - + [ - "destination-update", - result_create_stream[0], - "--delimiter", - ",", - "--text", - ] - ).splitlines() - assert_headers_in_lines(headers, result_update_stream) - - exec_test_command( +def test_stream_history_view_error(): + result = exec_failing_test_command( BASE_CMDS["streams"] + [ - "destination-delete", - result_create_stream[0], + "history-view", + "1", "--delimiter", ",", "--text", - ] - ).splitlines() - - exec_test_command( - BASE_CMDS["streams"] - + ["destination-view", result_create_stream[0], "--delimiter", ",", "--text"] - ) + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Stream not found" in result -def test_list_streams(): +def test_list_destinations(): result = exec_test_command( BASE_CMDS["streams"] + ["list", "--delimiter", ",", "--text"] ) @@ -148,12 +90,9 @@ def test_list_streams(): headers = [ "created", "created_by", - "destinations.details.access_key_id", - "destinations.details.bucket_name", - "destinations.details.host", - "destinations.details.path", - "details.cluster_ids", + "destinations.details.access_key_id", "destinations.details.bucket_name", "destinations.details.host" , "destinations.details.path", "details.cluster_ids", "details.is_auto_add_all_clusters_enabled", + "details", "id", "label", "status", @@ -165,22 +104,33 @@ def test_list_streams(): assert_headers_in_lines(headers, lines) -def test_create_stream_invalid_destination_error(): +def test_update_stream_error(): result = exec_failing_test_command( BASE_CMDS["streams"] + [ - "create", - "--label", - "test", - "--type", - "audit_logs", - "--destinations", - "12341234", + "update", + "1", "--delimiter", ",", "--text", ], expected_code=ExitCodes.REQUEST_FAILED, ) - assert "Request failed: 400" in result - assert "Destination not found" in result + assert "Request failed: 404" in result + assert "Stream not found" in result + + +def test_view_stream_error(): + result = exec_failing_test_command( + BASE_CMDS["streams"] + + [ + "view", + "1", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 404" in result + assert "Stream not found" in result From 56185cba7fbde28f83dc84a076a2ec3c56764250 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Tue, 28 Jul 2026 11:43:48 +0200 Subject: [PATCH 3/5] Apply code review suggestions --- tests/integration/streams/fixtures.py | 12 +++++++----- tests/integration/streams/test_destination.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/integration/streams/fixtures.py b/tests/integration/streams/fixtures.py index 66aa3e34d..1e64c2f09 100644 --- a/tests/integration/streams/fixtures.py +++ b/tests/integration/streams/fixtures.py @@ -83,11 +83,11 @@ def create_object_storage_keys(): "--delimiter", ",", "--format", - "access_key,id", + "access_key,secret_key,id", ] ).split(",") - yield result_keys[0], test_bucket["label"], test_bucket["s3_endpoint"] - delete_target_id("object-storage", str(result_keys[1]), "keys-delete") + yield result_keys[0], result_keys[1], test_bucket["label"], test_bucket["s3_endpoint"] + delete_target_id("object-storage", str(result_keys[2]), "keys-delete") @pytest.fixture(scope="function") @@ -104,11 +104,13 @@ def create_destination_akamai_object_storage_type(create_object_storage_keys): "--type", "akamai_object_storage", "--details.host", - create_object_storage_keys[2], + create_object_storage_keys[3], "--details.bucket_name", - create_object_storage_keys[1], + create_object_storage_keys[2], "--details.path", "audit-logs", + "--details.access_key_secret", + create_object_storage_keys[1], "--details.access_key_id", create_object_storage_keys[0], "--delimiter", diff --git a/tests/integration/streams/test_destination.py b/tests/integration/streams/test_destination.py index a50156c0d..b1bb97dfd 100644 --- a/tests/integration/streams/test_destination.py +++ b/tests/integration/streams/test_destination.py @@ -119,7 +119,7 @@ def test_remove_destination_error(): assert "Destination not found" in result -def test_view_delete_destination(create_destination_akamai_object_storage_type): +def test_create_view_delete_destination(create_destination_akamai_object_storage_type): result_view = exec_test_command( BASE_CMDS["streams"] + [ From 3202789ba304a372b69e17c98d5eb0379c6487fb Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Wed, 4 Nov 2026 17:15:44 +0100 Subject: [PATCH 4/5] Adjusts ACLP create destination test to related fix and create test test_create_view_stream --- tests/integration/helpers.py | 41 +++++++- tests/integration/streams/fixtures.py | 93 +++++++++++++++---- tests/integration/streams/test_destination.py | 48 +++++++--- tests/integration/streams/test_streams.py | 64 +++++++++++-- 4 files changed, 208 insertions(+), 38 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index e20072c91..90d9dab9d 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -64,6 +64,18 @@ ] BASE_CMDS = {module: ["linode-cli", module] for module in MODULES} +SENSITIVE_ARG_NAMES = { + "--access_key_secret", + "--access_key", + "--details.access_key_secret", + "--details.access_key_id", + "--token", + "--password", + "--secret", + "--secret_key", + "--bucket_access", +} + def get_random_text(length: int = 10): return "".join(random.choice(ascii_lowercase) for _ in range(length)) @@ -91,7 +103,7 @@ def exec_test_command(args: List[str]): if process.returncode != 0: raise RuntimeError( f"Command failed with exit code {process.returncode}\n" - f"Command: {' '.join(args)}\n" + f"Command: {' '.join(_redact_args(args))}\n" f"Stdout:\n{process.stdout}\n" f"Stderr:\n{process.stderr}" ) @@ -106,7 +118,7 @@ def exec_failing_test_command( if process.returncode != expected_code: raise AssertionError( f"Expected exit code {expected_code}, got {process.returncode}\n" - f"Command: {' '.join(args)}\n" + f"Command: {' '.join(_redact_args(args))}\n" f"Stdout:\n{process.stdout}\n" f"Stderr: {process.stderr}" ) @@ -255,3 +267,28 @@ def check_attribute_value( ) -> bool: result = view_command_attribute(command, action, item_id, attribute) return expected_val in result + + +def _redact_args(args: List[str]) -> List[str]: + redacted = [] + hide_next = False + for arg in args: + if hide_next: + redacted.append("***REDACTED***") + hide_next = False + continue + + # handle `--flag value` form + if arg in SENSITIVE_ARG_NAMES: + redacted.append(arg) + hide_next = True + continue + + # handle `--flag=value` form + if "=" in arg and arg.split("=", 1)[0] in SENSITIVE_ARG_NAMES: + flag, _ = arg.split("=", 1) + redacted.append(f"{flag}=***REDACTED***") + continue + + redacted.append(arg) + return redacted diff --git a/tests/integration/streams/fixtures.py b/tests/integration/streams/fixtures.py index 1e64c2f09..a832cbcff 100644 --- a/tests/integration/streams/fixtures.py +++ b/tests/integration/streams/fixtures.py @@ -1,9 +1,12 @@ +import json import os from typing import Any, Dict import pytest import requests +from linodecli import ExitCodes +from linodecli.cli import logger from tests.integration.helpers import ( BASE_CMDS, delete_target_id, @@ -40,10 +43,10 @@ def get_object_storage_buckets() -> Dict[str, Any]: return response.json() -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def create_stream(create_destination_akamai_object_storage_type): label = get_random_text(8) + "_stream_cli_test" - result_create_stream = exec_test_command( + result_create = exec_test_command( BASE_CMDS["streams"] + [ "create", @@ -52,19 +55,26 @@ def create_stream(create_destination_akamai_object_storage_type): "--type", "audit_logs", "--destinations", - create_destination_akamai_object_storage_type[0], - "--delimiter", - ",", - "--text", - ] - ).splitlines() - yield result_create_stream - delete_target_id("streams", str(result_create_stream[1]), "delete") + str(create_destination_akamai_object_storage_type["id"]), + "--json", + ], + ) + result_create_json = json.loads(result_create)[0] + yield result_create_json + wait_for_stream_status(str(result_create_json["id"]), "active") + delete_target_id( + "streams", + str(result_create_json["id"]), + ) @pytest.fixture def create_object_storage_keys(): label = get_random_text(8) + "_destination_cli_test" + if get_object_storage_buckets()["data"][0] is None: + raise ValueError( + "There is no object storage bucket available in your account. Cannot run test." + ) test_bucket = get_object_storage_buckets()["data"][0] result_keys = exec_test_command( BASE_CMDS["object-storage"] @@ -86,7 +96,9 @@ def create_object_storage_keys(): "access_key,secret_key,id", ] ).split(",") - yield result_keys[0], result_keys[1], test_bucket["label"], test_bucket["s3_endpoint"] + yield result_keys[0], result_keys[1], test_bucket["label"], test_bucket[ + "s3_endpoint" + ] delete_target_id("object-storage", str(result_keys[2]), "keys-delete") @@ -115,10 +127,59 @@ def create_destination_akamai_object_storage_type(create_object_storage_keys): create_object_storage_keys[0], "--delimiter", ",", - "--text", + "--json", ] - ).splitlines() - yield result_create_destination - delete_target_id( - "streams", str(result_create_destination[0]), "destination-delete" ) + create_destination_json = json.loads(result_create_destination) + yield create_destination_json[0] + try: + exec_test_command( + BASE_CMDS["streams"] + + [ + "destination-view", + str(create_destination_json[0]["id"]), + "--delimiter", + ",", + "--text", + ], + ) + except RuntimeError as error: + if "Request failed: 404" not in str(error): + raise + logger.debug("Destination already deleted, skipping deletion.") + else: + delete_target_id( + "streams", + str(create_destination_json[0]["id"]), + "destination-delete", + ) + + +def wait_for_stream_status( + stream_id: "str", status: "str", timeout=1800, interval=10 +): + import time + + must_end = time.time() + timeout + while time.time() < must_end: + time.sleep(interval) + try: + result = exec_test_command( + BASE_CMDS["streams"] + + [ + "view", + stream_id, + "--format", + "status", + "--text", + "--no-headers", + ] + ) + except RuntimeError as response_error: + if "Request failed: 404" in str(response_error): + continue + else: + raise RuntimeError(response_error) + if status == result: + return True + return False diff --git a/tests/integration/streams/test_destination.py b/tests/integration/streams/test_destination.py index b1bb97dfd..da2eec3af 100644 --- a/tests/integration/streams/test_destination.py +++ b/tests/integration/streams/test_destination.py @@ -1,3 +1,7 @@ +import json + +import pytest + from linodecli.exit_codes import ExitCodes from tests.integration.helpers import ( BASE_CMDS, @@ -5,12 +9,13 @@ exec_failing_test_command, exec_test_command, ) -from tests.integration.streams.fixtures import ( +from tests.integration.streams.fixtures import ( # noqa: F401 create_destination_akamai_object_storage_type, create_object_storage_keys, ) +@pytest.mark.smoke def test_list_destinations(): result = exec_test_command( BASE_CMDS["streams"] @@ -49,8 +54,7 @@ def test_create_destination_error(): ], expected_code=ExitCodes.REQUEST_FAILED, ) - assert "Request failed: 400" in result - assert "details,Must be of type Object" in result + assert "ambiguous option: --details could match" in result def test_view_destination_error(): @@ -108,7 +112,7 @@ def test_remove_destination_error(): BASE_CMDS["streams"] + [ "destination-delete", - "1", + "-1", "--delimiter", ",", "--text", @@ -119,24 +123,40 @@ def test_remove_destination_error(): assert "Destination not found" in result -def test_create_view_delete_destination(create_destination_akamai_object_storage_type): +def test_create_view_delete_destination( + create_destination_akamai_object_storage_type, +): result_view = exec_test_command( BASE_CMDS["streams"] + [ "destination-view", - create_destination_akamai_object_storage_type, - "--delimiter", - ",", - "--text", + str(create_destination_akamai_object_storage_type["id"]), + "--json", ], ) - assert result_view == "test" + result_view_json = json.loads(result_view)[0] + assert result_view_json["status"] == "active" + assert result_view_json["type"] == "akamai_object_storage" + assert result_view_json["version"] == 1 + + result_history_view = exec_test_command( + BASE_CMDS["streams"] + + [ + "destination-history-view", + str(create_destination_akamai_object_storage_type["id"]), + "--json", + ], + ) + result_history_view_json = json.loads(result_history_view)[0] + assert result_history_view_json["status"] == "active" + assert result_history_view_json["type"] == "akamai_object_storage" + assert result_history_view_json["version"] == 1 exec_test_command( BASE_CMDS["streams"] + [ - "delete", - create_destination_akamai_object_storage_type, + "destination-delete", + str(create_destination_akamai_object_storage_type["id"]), "--delimiter", ",", "--text", @@ -147,7 +167,7 @@ def test_create_view_delete_destination(create_destination_akamai_object_storage BASE_CMDS["streams"] + [ "destination-view", - create_destination_akamai_object_storage_type, + str(create_destination_akamai_object_storage_type["id"]), "--delimiter", ",", "--text", @@ -155,4 +175,4 @@ def test_create_view_delete_destination(create_destination_akamai_object_storage expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result - assert "Not found" in result + assert "Destination not found" in result diff --git a/tests/integration/streams/test_streams.py b/tests/integration/streams/test_streams.py index dbeb1b0f5..2a99e5f6f 100644 --- a/tests/integration/streams/test_streams.py +++ b/tests/integration/streams/test_streams.py @@ -1,3 +1,8 @@ +import json +import os + +import pytest + from linodecli.exit_codes import ExitCodes from tests.integration.helpers import ( BASE_CMDS, @@ -6,6 +11,12 @@ exec_failing_test_command, exec_test_command, ) +from tests.integration.streams.fixtures import ( # noqa: F401 + create_destination_akamai_object_storage_type, + create_object_storage_keys, + create_stream, + wait_for_stream_status, +) def test_help_streams(): @@ -45,7 +56,7 @@ def test_create_stream_error(): "--text", ], expected_code=ExitCodes.REQUEST_FAILED, - ) + ) assert "Request failed: 400" in result assert "Destination not found" in result @@ -61,7 +72,7 @@ def test_delete_stream_error(): "--text", ], expected_code=ExitCodes.REQUEST_FAILED, - ) + ) assert "Request failed: 404" in result assert "Not found" in result @@ -77,11 +88,12 @@ def test_stream_history_view_error(): "--text", ], expected_code=ExitCodes.REQUEST_FAILED, - ) + ) assert "Request failed: 404" in result assert "Stream not found" in result +@pytest.mark.smoke def test_list_destinations(): result = exec_test_command( BASE_CMDS["streams"] + ["list", "--delimiter", ",", "--text"] @@ -90,7 +102,11 @@ def test_list_destinations(): headers = [ "created", "created_by", - "destinations.details.access_key_id", "destinations.details.bucket_name", "destinations.details.host" , "destinations.details.path", "details.cluster_ids", + "destinations.details.access_key_id", + "destinations.details.bucket_name", + "destinations.details.host", + "destinations.details.path", + "details.cluster_ids", "details.is_auto_add_all_clusters_enabled", "details", "id", @@ -115,7 +131,7 @@ def test_update_stream_error(): "--text", ], expected_code=ExitCodes.REQUEST_FAILED, - ) + ) assert "Request failed: 404" in result assert "Stream not found" in result @@ -131,6 +147,42 @@ def test_view_stream_error(): "--text", ], expected_code=ExitCodes.REQUEST_FAILED, - ) + ) assert "Request failed: 404" in result assert "Stream not found" in result + + +@pytest.mark.skipif( + os.environ.get("RUN_LONG_TESTS", None) != "True", + reason="Skipping long-running Test, to run set RUN_LONG_TESTS=True", +) +def test_create_view_stream( + create_stream, +): + assert create_stream["destinations"][0]["details"]["access_key_id"] + assert create_stream["destinations"][0]["details"]["bucket_name"] + assert create_stream["destinations"][0]["details"]["host"] + assert create_stream["destinations"][0]["details"]["path"] + assert create_stream["destinations"][0]["type"] == "akamai_object_storage" + assert create_stream["status"] == "provisioning" + assert create_stream["type"] == "audit_logs" + + wait_for_stream_status(str(create_stream["id"]), "active") + result_view = exec_test_command( + BASE_CMDS["streams"] + + [ + "view", + str(create_stream["id"]), + "--json", + ], + ) + result_view_json = json.loads(result_view)[0] + assert result_view_json["destinations"][0]["details"]["access_key_id"] + assert result_view_json["destinations"][0]["details"]["bucket_name"] + assert result_view_json["destinations"][0]["details"]["host"] + assert result_view_json["destinations"][0]["details"]["path"] + assert ( + result_view_json["destinations"][0]["type"] == "akamai_object_storage" + ) + assert result_view_json["status"] == "active" + assert result_view_json["type"] == "audit_logs" From 52a3b538475066bf2158f23234838443d2cfb471 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Wed, 25 Nov 2026 16:10:04 +0100 Subject: [PATCH 5/5] Add code review suggestions --- tests/integration/helpers.py | 2 +- tests/integration/streams/fixtures.py | 61 +++++++++++------------ tests/integration/streams/test_streams.py | 6 ++- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 90d9dab9d..b70ea32a0 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -286,7 +286,7 @@ def _redact_args(args: List[str]) -> List[str]: # handle `--flag=value` form if "=" in arg and arg.split("=", 1)[0] in SENSITIVE_ARG_NAMES: - flag, _ = arg.split("=", 1) + flag = arg.split("=", 1)[0] redacted.append(f"{flag}=***REDACTED***") continue diff --git a/tests/integration/streams/fixtures.py b/tests/integration/streams/fixtures.py index a832cbcff..4009fb49c 100644 --- a/tests/integration/streams/fixtures.py +++ b/tests/integration/streams/fixtures.py @@ -5,7 +5,6 @@ import pytest import requests -from linodecli import ExitCodes from linodecli.cli import logger from tests.integration.helpers import ( BASE_CMDS, @@ -13,6 +12,7 @@ exec_test_command, get_random_region_with_caps, get_random_text, + wait_for_condition, ) @@ -21,12 +21,12 @@ def get_object_storage_buckets() -> Dict[str, Any]: if token is None: raise ValueError("LINODE_CLI_TOKEN environment variable is not set. ") host = os.getenv("LINODE_CLI_API_HOST") - if token is None: + if host is None: raise ValueError( "LINODE_CLI_API_HOST environment variable is not set. " ) version = os.getenv("LINODE_CLI_API_VERSION") - if token is None: + if version is None: raise ValueError( "LINODE_CLI_API_VERSION environment variable is not set. " ) @@ -61,7 +61,13 @@ def create_stream(create_destination_akamai_object_storage_type): ) result_create_json = json.loads(result_create)[0] yield result_create_json - wait_for_stream_status(str(result_create_json["id"]), "active") + wait_for_condition( + 20, + 3000, + is_expected_stream_status, + str(result_create_json["id"]), + "active", + ) delete_target_id( "streams", str(result_create_json["id"]), @@ -155,31 +161,22 @@ def create_destination_akamai_object_storage_type(create_object_storage_keys): ) -def wait_for_stream_status( - stream_id: "str", status: "str", timeout=1800, interval=10 -): - import time - - must_end = time.time() + timeout - while time.time() < must_end: - time.sleep(interval) - try: - result = exec_test_command( - BASE_CMDS["streams"] - + [ - "view", - stream_id, - "--format", - "status", - "--text", - "--no-headers", - ] - ) - except RuntimeError as response_error: - if "Request failed: 404" in str(response_error): - continue - else: - raise RuntimeError(response_error) - if status == result: - return True - return False +def is_expected_stream_status(stream_id: "str", status: "str"): + try: + result = exec_test_command( + BASE_CMDS["streams"] + + [ + "view", + stream_id, + "--format", + "status", + "--text", + "--no-headers", + ] + ) + except RuntimeError as response_error: + if "Request failed: 404" not in str(response_error): + return False + else: + raise RuntimeError(response_error) + return status == result diff --git a/tests/integration/streams/test_streams.py b/tests/integration/streams/test_streams.py index 2a99e5f6f..4ef173667 100644 --- a/tests/integration/streams/test_streams.py +++ b/tests/integration/streams/test_streams.py @@ -10,11 +10,13 @@ assert_help_actions_list, exec_failing_test_command, exec_test_command, + wait_for_condition, ) from tests.integration.streams.fixtures import ( # noqa: F401 create_destination_akamai_object_storage_type, create_object_storage_keys, create_stream, + is_expected_stream_status, wait_for_stream_status, ) @@ -167,7 +169,9 @@ def test_create_view_stream( assert create_stream["status"] == "provisioning" assert create_stream["type"] == "audit_logs" - wait_for_stream_status(str(create_stream["id"]), "active") + wait_for_condition( + 20, 3000, is_expected_stream_status, str(create_stream["id"]), "active" + ) result_view = exec_test_command( BASE_CMDS["streams"] + [