@@ -108,6 +108,73 @@ def test_list_instances_with_filters(self, client, sample_instance):
108108 assert call_kwargs ["limit" ] == 50
109109 assert call_kwargs ["offset" ] == 10
110110
111+ def test_list_instances_with_search (self , client , sample_instance ):
112+ """Test instance listing with search parameter."""
113+ mock_result = InstanceQueryResult (
114+ instances = [sample_instance ],
115+ total = 1 ,
116+ limit = 100 ,
117+ offset = 0 ,
118+ )
119+
120+ with patch ("redis_sre_agent.core.instances.query_instances" ) as mock_query :
121+ mock_query .return_value = mock_result
122+
123+ response = client .get (
124+ "/api/v1/instances" ,
125+ params = {"search" : "test-redis" },
126+ )
127+
128+ assert response .status_code == 200
129+ mock_query .assert_called_once ()
130+ call_kwargs = mock_query .call_args [1 ]
131+ assert call_kwargs ["search" ] == "test-redis"
132+
133+ def test_list_instances_with_empty_search (self , client , sample_instance ):
134+ """Test instance listing with empty search string."""
135+ mock_result = InstanceQueryResult (
136+ instances = [sample_instance ],
137+ total = 1 ,
138+ limit = 100 ,
139+ offset = 0 ,
140+ )
141+
142+ with patch ("redis_sre_agent.core.instances.query_instances" ) as mock_query :
143+ mock_query .return_value = mock_result
144+
145+ response = client .get (
146+ "/api/v1/instances" ,
147+ params = {"search" : "" },
148+ )
149+
150+ assert response .status_code == 200
151+ mock_query .assert_called_once ()
152+ call_kwargs = mock_query .call_args [1 ]
153+ # Empty string should be passed as empty (falsy)
154+ assert call_kwargs ["search" ] == ""
155+
156+ def test_list_instances_with_instance_type_filter (self , client , sample_instance ):
157+ """Test instance listing with instance_type filter."""
158+ mock_result = InstanceQueryResult (
159+ instances = [sample_instance ],
160+ total = 1 ,
161+ limit = 100 ,
162+ offset = 0 ,
163+ )
164+
165+ with patch ("redis_sre_agent.core.instances.query_instances" ) as mock_query :
166+ mock_query .return_value = mock_result
167+
168+ response = client .get (
169+ "/api/v1/instances" ,
170+ params = {"instance_type" : "redis_cloud" },
171+ )
172+
173+ assert response .status_code == 200
174+ mock_query .assert_called_once ()
175+ call_kwargs = mock_query .call_args [1 ]
176+ assert call_kwargs ["instance_type" ] == "redis_cloud"
177+
111178 def test_get_instance_success (self , client , sample_instance ):
112179 """Test successful instance retrieval."""
113180 with patch ("redis_sre_agent.core.instances.get_instances" ) as mock_get :
0 commit comments