go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/tq/internal/sweep/helpers_test.go (about)

     1  // Copyright 2020 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 sweep
    16  
    17  import (
    18  	"testing"
    19  
    20  	"go.chromium.org/luci/server/tq/internal/partition"
    21  	"go.chromium.org/luci/server/tq/internal/reminder"
    22  
    23  	. "github.com/smartystreets/goconvey/convey"
    24  )
    25  
    26  func TestHelpers(t *testing.T) {
    27  	t.Parallel()
    28  
    29  	const keySpaceBytes = 16
    30  
    31  	Convey("OnlyLeased", t, func() {
    32  		reminders := []*reminder.Reminder{
    33  			// Each key be exactly 2*keySpaceBytes chars long.
    34  			{ID: "00000000000000000000000000000001"},
    35  			{ID: "00000000000000000000000000000005"},
    36  			{ID: "00000000000000000000000000000009"},
    37  			{ID: "0000000000000000000000000000000f"}, // ie 15
    38  		}
    39  		leased := partition.SortedPartitions{partition.FromInts(5, 9)}
    40  		So(onlyLeased(reminders, leased, keySpaceBytes), ShouldResemble, []*reminder.Reminder{
    41  			{ID: "00000000000000000000000000000005"},
    42  		})
    43  	})
    44  }