[buildbucket] Add an assertion in search.py

Also add a comment to clarify a part of the test

R=tandrii@chromium.org

Change-Id: I4783065440d502d07f7efbec932f183b3a596374
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/1597675
Commit-Queue: Nodir Turakulov <nodir@chromium.org>
Auto-Submit: Nodir Turakulov <nodir@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/recipe_modules/buildbucket/tests/search.py b/recipe_modules/buildbucket/tests/search.py
index 8e5dc02..bb9098a 100644
--- a/recipe_modules/buildbucket/tests/search.py
+++ b/recipe_modules/buildbucket/tests/search.py
@@ -20,12 +20,14 @@
 
 
 def RunSteps(api):
+  limit = api.properties.get('limit')
   builds = api.buildbucket.search(
       rpc_pb2.BuildPredicate(
         gerrit_changes=list(api.buildbucket.build.input.gerrit_changes),
       ),
-      limit=api.properties.get('limit'),
+      limit=limit,
   )
+  assert limit is None or len(builds) <= limit
   pres = api.step.active_result.presentation
   for b in builds:
     pres.logs['build %s' % b.id] = json_format.MessageToJson(b).splitlines()
@@ -72,6 +74,7 @@
       api.properties(limit=5) +
       api.buildbucket.simulated_search_results([
         build_pb2.Build(id=i+1, status=common_pb2.SUCCESS)
+        # Returning more to test trimming of the returned list.
         for i in xrange(10)
       ])
   )