1- package utils
1+ package connmysql
22
33import (
4- "log/slog"
54 "regexp"
65 "testing"
76
87 "github.com/stretchr/testify/assert"
98 "github.com/stretchr/testify/require"
10- "go.temporal.io/sdk/log"
119
1210 "github.com/PeerDB-io/peerdb/flow/generated/protos"
1311)
@@ -16,13 +14,13 @@ func TestUUIDToBigIntRoundTrip(t *testing.T) {
1614 cases := []struct {
1715 name string
1816 uuid string
19- casing HexCasing
17+ casing hexCasing
2018 }{
21- {"lower case v4" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , Lower },
22- {"upper case v7" , "017F22E2-79B0-7CC3-98C4-DC0C0C07398F" , Upper },
23- {"zero" , "00000000-0000-0000-0000-000000000000" , Lower },
24- {"max" , "ffffffff-ffff-ffff-ffff-ffffffffffff" , Lower },
25- {"all digits" , "01234567-8901-2345-6789-012345678901" , Lower },
19+ {"lower case v4" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , hexCasingLower },
20+ {"upper case v7" , "017F22E2-79B0-7CC3-98C4-DC0C0C07398F" , hexCasingUpper },
21+ {"zero" , "00000000-0000-0000-0000-000000000000" , hexCasingLower },
22+ {"max" , "ffffffff-ffff-ffff-ffff-ffffffffffff" , hexCasingLower },
23+ {"all digits" , "01234567-8901-2345-6789-012345678901" , hexCasingLower },
2624 }
2725 for _ , tc := range cases {
2826 t .Run (tc .name , func (t * testing.T ) {
@@ -53,44 +51,43 @@ func TestDetectUUIDCase(t *testing.T) {
5351 minVal string
5452 maxVal string
5553 expectIsUUID bool
56- expectCasing HexCasing
54+ expectCasing hexCasing
5755 }{
58- {"both lower" , "00000000-0000-0000-0000-000000000000" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , true , Lower },
59- {"both upper" , "00000000-0000-0000-0000-000000000000" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , true , Upper },
60- {"all digits" , "01234567-8901-2345-6789-012345678901" , "09234567-8901-2345-6789-012345678901" , true , Lower },
61- {"digits min, upper max" , "01234567-8901-2345-6789-012345678901" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , true , Upper },
62- {"lower min, digits max" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , "01234567-8901-2345-6789-012345678901" , true , Lower },
63- {"mixed case across bounds" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , false , Unknown },
64- {"mixed case within a bound" , "00000000-0000-0000-0000-000000000000" , "F47ac10b-58cc-4372-a567-0e02b2c3d479" , false , Unknown },
65- {"non-uuid" , "apple" , "banana" , false , Unknown },
56+ {"both lower" , "00000000-0000-0000-0000-000000000000" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , true , hexCasingLower },
57+ {"both upper" , "00000000-0000-0000-0000-000000000000" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , true , hexCasingUpper },
58+ {"all digits" , "01234567-8901-2345-6789-012345678901" , "09234567-8901-2345-6789-012345678901" , true , hexCasingLower },
59+ {"digits min, upper max" , "01234567-8901-2345-6789-012345678901" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , true , hexCasingUpper },
60+ {"lower min, digits max" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , "01234567-8901-2345-6789-012345678901" , true , hexCasingLower },
61+ {"mixed case across bounds" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , false , hexCasingUnknown },
62+ {"mixed case within a bound" , "00000000-0000-0000-0000-000000000000" , "F47ac10b-58cc-4372-a567-0e02b2c3d479" , false , hexCasingUnknown },
63+ {"non-uuid" , "apple" , "banana" , false , hexCasingUnknown },
6664 }
6765 for _ , tc := range cases {
6866 t .Run (tc .name , func (t * testing.T ) {
69- isUUID , hexCasing := DetectUuidWithHexCasing (tc .minVal , tc .maxVal )
67+ isUUID , casing := detectUuidWithHexCasing (tc .minVal , tc .maxVal )
7068 assert .Equal (t , tc .expectIsUUID , isUUID )
71- assert .Equal (t , tc .expectCasing , hexCasing )
69+ assert .Equal (t , tc .expectCasing , casing )
7270 })
7371 }
7472}
7573
76- func TestAddPartitionsWithRangeUUID (t * testing.T ) {
74+ func TestBuildUuidStringPartitions (t * testing.T ) {
7775 cases := []struct {
7876 name string
7977 minV string
8078 maxV string
8179 expectedCase * regexp.Regexp
8280 }{
83- {"lower" , "018f6e7a-1b2c-7def-8a3b-1c2d3e4f5a6b" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , UuidLowerRe },
84- {"upper" , "018F6E7A-1B2C-7DEF-8A3B-1C2D3E4F5A6B" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , UuidUpperRe },
81+ {"lower" , "018f6e7a-1b2c-7def-8a3b-1c2d3e4f5a6b" , "f47ac10b-58cc-4372-a567-0e02b2c3d479" , uuidLowerRe },
82+ {"upper" , "018F6E7A-1B2C-7DEF-8A3B-1C2D3E4F5A6B" , "F47AC10B-58CC-4372-A567-0E02B2C3D479" , uuidUpperRe },
8583 }
8684 const numPartitions = 32
8785 for _ , tc := range cases {
8886 t .Run (tc .name , func (t * testing.T ) {
89- p := NewPartitionHelper (log .NewStructuredLogger (slog .Default ()))
90- isUUID , hexCasing := DetectUuidWithHexCasing (tc .minV , tc .maxV )
87+ isUUID , casing := detectUuidWithHexCasing (tc .minV , tc .maxV )
9188 require .True (t , isUUID )
92- require . NoError ( t , p . AddUuidStringPartitionsWithRange (tc .minV , tc .maxV , hexCasing , numPartitions ) )
93- parts := p . GetPartitions ( )
89+ parts , err := buildUuidStringPartitions (tc .minV , tc .maxV , casing , numPartitions )
90+ require . NoError ( t , err )
9491 require .Len (t , parts , numPartitions )
9592
9693 prevEnd := ""
@@ -121,7 +118,7 @@ func TestAddPartitionsWithRangeUUID(t *testing.T) {
121118 }
122119}
123120
124- func TestAddPartitionsWithRangeUUIDSinglePartition (t * testing.T ) {
121+ func TestBuildUuidStringPartitionsSinglePartition (t * testing.T ) {
125122 uuid1 := "018f6e7a-1b2c-7def-8a3b-1c2d3e4f5a6b"
126123 uuid2 := "f47ac10b-58cc-4372-a567-0e02b2c3d479"
127124 cases := []struct {
@@ -135,11 +132,10 @@ func TestAddPartitionsWithRangeUUIDSinglePartition(t *testing.T) {
135132 }
136133 for _ , tc := range cases {
137134 t .Run (tc .name , func (t * testing.T ) {
138- p := NewPartitionHelper (log .NewStructuredLogger (slog .Default ()))
139- isUUID , hexCasing := DetectUuidWithHexCasing (tc .minV , tc .maxV )
135+ isUUID , casing := detectUuidWithHexCasing (tc .minV , tc .maxV )
140136 require .True (t , isUUID )
141- require . NoError ( t , p . AddUuidStringPartitionsWithRange (tc .minV , tc .maxV , hexCasing , tc .numPartitions ) )
142- parts := p . GetPartitions ( )
137+ parts , err := buildUuidStringPartitions (tc .minV , tc .maxV , casing , tc .numPartitions )
138+ require . NoError ( t , err )
143139 require .Len (t , parts , 1 )
144140 sr , ok := parts [0 ].Range .Range .(* protos.PartitionRange_StringRange )
145141 require .True (t , ok )
0 commit comments