go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/pagination/page_size_test.go (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package pagination
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/smartystreets/goconvey/convey"
    21  	. "go.chromium.org/luci/common/testing/assertions"
    22  )
    23  
    24  func TestPageSizeLimiter(t *testing.T) {
    25  	t.Parallel()
    26  
    27  	Convey(`PageSizeLimiter`, t, func() {
    28  		psl := PageSizeLimiter{
    29  			Max:     1000,
    30  			Default: 10,
    31  		}
    32  
    33  		Convey(`Adjust works`, func() {
    34  			So(psl.Adjust(0), ShouldEqual, 10)
    35  			So(psl.Adjust(10000), ShouldEqual, 1000)
    36  			So(psl.Adjust(500), ShouldEqual, 500)
    37  			So(psl.Adjust(5), ShouldEqual, 5)
    38  		})
    39  	})
    40  }
    41  
    42  func TestValidatePageSize(t *testing.T) {
    43  	t.Parallel()
    44  
    45  	Convey(`ValidatePageSize`, t, func() {
    46  		Convey(`Positive`, func() {
    47  			So(ValidatePageSize(10), ShouldBeNil)
    48  		})
    49  		Convey(`Zero`, func() {
    50  			So(ValidatePageSize(0), ShouldBeNil)
    51  		})
    52  		Convey(`Negative`, func() {
    53  			So(ValidatePageSize(-10), ShouldErrLike, "negative")
    54  		})
    55  	})
    56  }