Repository: getmoto/moto

Issue:
Limit argument in descibe_stream is not working when mock kinesis
Hi,
When I was using moto to test my kinesis code, I found that the Limit argument is not effective. For example, I just want to return only 1 shard information, I will use Limit=1:
`self.client.describe_stream(StreamName=stream_name, Limit=1)['StreamDescription']['Shards']`
But when using moto, it would return all the shards it has. Could you add the ability to accept this parameter, and return specified number of shards?
Thanks!



Discussion:
Thanks; adding as a feature request.

Resolving patch:
diff --git a/moto/kinesis/models.py b/moto/kinesis/models.py
--- a/moto/kinesis/models.py
+++ b/moto/kinesis/models.py
@@ -209,15 +209,17 @@ def put_record(
         sequence_number = shard.put_record(partition_key, data, explicit_hash_key)
         return sequence_number, shard.shard_id
 
-    def to_json(self):
+    def to_json(self, shard_limit=None):
+        all_shards = list(self.shards.values())
+        requested_shards = all_shards[0 : shard_limit or len(all_shards)]
         return {
             "StreamDescription": {
                 "StreamARN": self.arn,
                 "StreamName": self.stream_name,
                 "StreamStatus": self.status,
-                "HasMoreShards": False,
+                "HasMoreShards": len(requested_shards) != len(all_shards),
                 "RetentionPeriodHours": self.retention_period_hours,
-                "Shards": [shard.to_json() for shard in self.shards.values()],
+                "Shards": [shard.to_json() for shard in requested_shards],
             }
         }
 
diff --git a/moto/kinesis/responses.py b/moto/kinesis/responses.py
--- a/moto/kinesis/responses.py
+++ b/moto/kinesis/responses.py
@@ -26,8 +26,9 @@ def create_stream(self):
 
     def describe_stream(self):
         stream_name = self.parameters.get("StreamName")
+        limit = self.parameters.get("Limit")
         stream = self.kinesis_backend.describe_stream(stream_name)
-        return json.dumps(stream.to_json())
+        return json.dumps(stream.to_json(shard_limit=limit))
 
     def describe_stream_summary(self):
         stream_name = self.parameters.get("StreamName")


Test patch:
diff --git a/tests/test_kinesis/test_kinesis_boto3.py b/tests/test_kinesis/test_kinesis_boto3.py
--- a/tests/test_kinesis/test_kinesis_boto3.py
+++ b/tests/test_kinesis/test_kinesis_boto3.py
@@ -5,6 +5,36 @@
 import sure  # noqa
 
 
+@mock_kinesis
+def test_describe_stream_limit_parameter():
+    client = boto3.client("kinesis", region_name="us-west-2")
+    stream_name = "my_stream"
+
+    client.create_stream(StreamName=stream_name, ShardCount=5)
+
+    without_filter = client.describe_stream(StreamName=stream_name)["StreamDescription"]
+    without_filter["Shards"].should.have.length_of(5)
+    without_filter["HasMoreShards"].should.equal(False)
+
+    with_filter = client.describe_stream(StreamName=stream_name, Limit=2)[
+        "StreamDescription"
+    ]
+    with_filter["Shards"].should.have.length_of(2)
+    with_filter["HasMoreShards"].should.equal(True)
+
+    with_filter = client.describe_stream(StreamName=stream_name, Limit=5)[
+        "StreamDescription"
+    ]
+    with_filter["Shards"].should.have.length_of(5)
+    with_filter["HasMoreShards"].should.equal(False)
+
+    with_filter = client.describe_stream(StreamName=stream_name, Limit=6)[
+        "StreamDescription"
+    ]
+    with_filter["Shards"].should.have.length_of(5)
+    with_filter["HasMoreShards"].should.equal(False)
+
+
 @mock_kinesis
 def test_split_shard():
     conn = boto3.client("kinesis", region_name="us-west-2")