github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/storage/tsdb/util_test.go (about)

     1  package tsdb
     2  
     3  import (
     4  	"crypto/rand"
     5  	"testing"
     6  
     7  	"github.com/oklog/ulid"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestHashBlockID(t *testing.T) {
    12  	tests := []struct {
    13  		first         ulid.ULID
    14  		second        ulid.ULID
    15  		expectedEqual bool
    16  	}{
    17  		{
    18  			first:         ulid.MustNew(10, nil),
    19  			second:        ulid.MustNew(10, nil),
    20  			expectedEqual: true,
    21  		},
    22  		{
    23  			first:         ulid.MustNew(10, nil),
    24  			second:        ulid.MustNew(20, nil),
    25  			expectedEqual: false,
    26  		},
    27  		{
    28  			first:         ulid.MustNew(10, rand.Reader),
    29  			second:        ulid.MustNew(10, rand.Reader),
    30  			expectedEqual: false,
    31  		},
    32  	}
    33  
    34  	for _, testCase := range tests {
    35  		firstHash := HashBlockID(testCase.first)
    36  		secondHash := HashBlockID(testCase.second)
    37  		assert.Equal(t, testCase.expectedEqual, firstHash == secondHash)
    38  	}
    39  }