|
13 | 13 |
|
14 | 14 | from localstack import config |
15 | 15 | from localstack.aws.api.lambda_ import Runtime |
16 | | -from localstack.services.sqs.constants import DEFAULT_MAXIMUM_MESSAGE_SIZE |
| 16 | +from localstack.services.sqs.constants import DEFAULT_MAXIMUM_MESSAGE_SIZE, SQS_UUID_STRING_SEED |
17 | 17 | from localstack.services.sqs.models import sqs_stores |
18 | 18 | from localstack.services.sqs.provider import MAX_NUMBER_OF_MESSAGES |
19 | | -from localstack.services.sqs.utils import parse_queue_url |
| 19 | +from localstack.services.sqs.utils import parse_queue_url, token_generator |
20 | 20 | from localstack.testing.aws.util import is_aws_cloud |
21 | 21 | from localstack.testing.config import ( |
22 | 22 | SECONDARY_TEST_AWS_ACCESS_KEY_ID, |
|
28 | 28 | from localstack.utils.aws import arns |
29 | 29 | from localstack.utils.aws.arns import get_partition |
30 | 30 | from localstack.utils.aws.request_context import mock_aws_request_headers |
31 | | -from localstack.utils.common import poll_condition, retry, short_uid, to_str |
| 31 | +from localstack.utils.common import poll_condition, retry, short_uid, short_uid_from_seed, to_str |
32 | 32 | from localstack.utils.urls import localstack_host |
33 | 33 | from tests.aws.services.lambda_.functions import lambda_integration |
34 | 34 | from tests.aws.services.lambda_.test_lambda import TEST_LAMBDA_PYTHON |
@@ -143,6 +143,60 @@ def test_list_queues(self, sqs_create_queue, aws_client): |
143 | 143 | result = aws_client.sqs.list_queues(QueueNamePrefix="nonexisting-queue-") |
144 | 144 | assert "QueueUrls" not in result |
145 | 145 |
|
| 146 | + @markers.aws.validated |
| 147 | + def test_list_queues_pagination(self, sqs_create_queue, aws_client, snapshot): |
| 148 | + queue_list_length = 10 |
| 149 | + # ensures test is unique and prevents conflict in case of parrallel test runs |
| 150 | + test_output_identifier = short_uid_from_seed(SQS_UUID_STRING_SEED) |
| 151 | + max_result_1 = 2 |
| 152 | + max_result_2 = 10 |
| 153 | + |
| 154 | + queue_names = [f"{test_output_identifier}-test-queue-{i}" for i in range(queue_list_length)] |
| 155 | + |
| 156 | + queue_urls = [] |
| 157 | + for name in queue_names: |
| 158 | + sqs_create_queue(QueueName=name) |
| 159 | + queue_url = aws_client.sqs.get_queue_url(QueueName=name)["QueueUrl"] |
| 160 | + assert queue_url.endswith(name) |
| 161 | + queue_urls.append(queue_url) |
| 162 | + |
| 163 | + list_all = aws_client.sqs.list_queues(QueueNamePrefix=test_output_identifier) |
| 164 | + assert "QueueUrls" in list_all |
| 165 | + assert len(list_all["QueueUrls"]) == queue_list_length |
| 166 | + snapshot.match("list_all", list_all) |
| 167 | + |
| 168 | + list_two_max = aws_client.sqs.list_queues( |
| 169 | + MaxResults=max_result_1, QueueNamePrefix=test_output_identifier |
| 170 | + ) |
| 171 | + assert "QueueUrls" in list_two_max |
| 172 | + assert "NextToken" in list_two_max |
| 173 | + assert len(list_two_max["QueueUrls"]) == max_result_1 |
| 174 | + snapshot.match("list_two_max", list_two_max) |
| 175 | + next_token = list_two_max["NextToken"] |
| 176 | + |
| 177 | + list_remaining = aws_client.sqs.list_queues( |
| 178 | + MaxResults=max_result_2, NextToken=next_token, QueueNamePrefix=test_output_identifier |
| 179 | + ) |
| 180 | + assert "QueueUrls" in list_remaining |
| 181 | + assert "NextToken" not in list_remaining |
| 182 | + assert len(list_remaining["QueueUrls"]) == max_result_2 - max_result_1 |
| 183 | + snapshot.match("list_remaining", list_remaining) |
| 184 | + |
| 185 | + snapshot.add_transformer( |
| 186 | + snapshot.transform.regex( |
| 187 | + r"https://sqs\.(.+?)\.amazonaws\.com", |
| 188 | + r"http://sqs.\1.localhost.localstack.cloud:4566", |
| 189 | + ) |
| 190 | + ) |
| 191 | + |
| 192 | + url = f"http://sqs.<region>.localhost.localstack.cloud:4566/111111111111/{test_output_identifier}-test-queue-{max_result_1 - 1}" |
| 193 | + snapshot.add_transformer( |
| 194 | + snapshot.transform.regex( |
| 195 | + r'("NextToken":\s*")[^"]*(")', |
| 196 | + r"\1" + token_generator(url) + r"\2", |
| 197 | + ) |
| 198 | + ) |
| 199 | + |
146 | 200 | @markers.aws.validated |
147 | 201 | def test_create_queue_and_get_attributes(self, sqs_queue, aws_sqs_client): |
148 | 202 | result = aws_sqs_client.get_queue_attributes( |
|
0 commit comments