@@ -213,6 +213,102 @@ func TestIterator_NonPaginatedResponse(t *testing.T) {
213213 }
214214}
215215
216+ // Test response with only count and results (no next/previous fields)
217+ // This is a common case when there are no results or only one page
218+ func TestIterator_CountAndResultsOnly (t * testing.T ) {
219+ // Test case 1: Empty results
220+ emptyResponse := Record {
221+ "count" : float64 (0 ),
222+ "results" : []any {},
223+ }
224+
225+ mockSession := & mockSessionForIterator {
226+ responses : map [string ]Renderable {
227+ "https://test.example.com:443/api/v1/resources/?name=vastdb-volume&page_size=10" : emptyResponse ,
228+ },
229+ }
230+
231+ mockRest := & DummyRest {
232+ ctx : context .Background (),
233+ Session : mockSession ,
234+ }
235+
236+ mockResource := & mockResourceForIterator {
237+ VastResource : & VastResource {
238+ resourcePath : "resources" ,
239+ resourceType : "TestResource" ,
240+ Rest : mockRest ,
241+ },
242+ mockSession : mockSession ,
243+ }
244+
245+ // Create iterator with query params
246+ iter := NewResourceIterator (context .Background (), mockResource , Params {"name" : "vastdb-volume" }, 10 )
247+
248+ // Should return empty RecordSet, not error
249+ records , err := iter .Next ()
250+ if err != nil {
251+ t .Fatalf ("Expected no error for empty results, got: %v" , err )
252+ }
253+ if len (records ) != 0 {
254+ t .Errorf ("Expected 0 items, got %d" , len (records ))
255+ }
256+ if iter .Count () != 0 {
257+ t .Errorf ("Expected count of 0, got %d" , iter .Count ())
258+ }
259+ if iter .HasNext () {
260+ t .Error ("Expected HasNext to be false when no next field" )
261+ }
262+
263+ // Test case 2: Single page with results (no next/previous)
264+ singlePageResponse := Record {
265+ "count" : float64 (2 ),
266+ "results" : []any {
267+ map [string ]any {"id" : float64 (1 ), "name" : "item1" },
268+ map [string ]any {"id" : float64 (2 ), "name" : "item2" },
269+ },
270+ }
271+
272+ mockSession2 := & mockSessionForIterator {
273+ responses : map [string ]Renderable {
274+ "https://test.example.com:443/api/v1/resources/?page_size=10" : singlePageResponse ,
275+ },
276+ }
277+
278+ mockRest2 := & DummyRest {
279+ ctx : context .Background (),
280+ Session : mockSession2 ,
281+ }
282+
283+ mockResource2 := & mockResourceForIterator {
284+ VastResource : & VastResource {
285+ resourcePath : "resources" ,
286+ resourceType : "TestResource" ,
287+ Rest : mockRest2 ,
288+ },
289+ mockSession : mockSession2 ,
290+ }
291+
292+ iter2 := NewResourceIterator (context .Background (), mockResource2 , Params {}, 10 )
293+
294+ records , err = iter2 .Next ()
295+ if err != nil {
296+ t .Fatalf ("Expected no error, got: %v" , err )
297+ }
298+ if len (records ) != 2 {
299+ t .Errorf ("Expected 2 items, got %d" , len (records ))
300+ }
301+ if iter2 .Count () != 2 {
302+ t .Errorf ("Expected count of 2, got %d" , iter2 .Count ())
303+ }
304+ if iter2 .HasNext () {
305+ t .Error ("Expected HasNext to be false when no next field" )
306+ }
307+ if iter2 .HasPrevious () {
308+ t .Error ("Expected HasPrevious to be false when no previous field" )
309+ }
310+ }
311+
216312// Test All() method
217313func TestIterator_All (t * testing.T ) {
218314 // Create mock responses with multiple pages
0 commit comments