github.com/weaviate/weaviate@v1.24.6/entities/filters/pagination_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package filters
    13  
    14  import (
    15  	"testing"
    16  
    17  	"github.com/stretchr/testify/assert"
    18  	"github.com/stretchr/testify/require"
    19  )
    20  
    21  func TestExtractPagination(t *testing.T) {
    22  	t.Run("without a limit present", func(t *testing.T) {
    23  		p, err := ExtractPaginationFromArgs(map[string]interface{}{})
    24  		require.Nil(t, err)
    25  		assert.Nil(t, p)
    26  	})
    27  
    28  	t.Run("with a limit present", func(t *testing.T) {
    29  		p, err := ExtractPaginationFromArgs(map[string]interface{}{
    30  			"limit": 25,
    31  		})
    32  		require.Nil(t, err)
    33  		require.NotNil(t, p)
    34  		assert.Equal(t, 0, p.Offset)
    35  		assert.Equal(t, 25, p.Limit)
    36  	})
    37  
    38  	t.Run("with a offset present", func(t *testing.T) {
    39  		p, err := ExtractPaginationFromArgs(map[string]interface{}{
    40  			"offset": 11,
    41  		})
    42  		require.Nil(t, err)
    43  		require.NotNil(t, p)
    44  		assert.Equal(t, 11, p.Offset)
    45  		assert.Equal(t, -1, p.Limit)
    46  	})
    47  
    48  	t.Run("with offset and limit present", func(t *testing.T) {
    49  		p, err := ExtractPaginationFromArgs(map[string]interface{}{
    50  			"offset": 11,
    51  			"limit":  25,
    52  		})
    53  		require.Nil(t, err)
    54  		require.NotNil(t, p)
    55  		assert.Equal(t, 11, p.Offset)
    56  		assert.Equal(t, 25, p.Limit)
    57  	})
    58  }