@@ -15,6 +15,7 @@ import (
1515 "strings"
1616 "testing"
1717 "time"
18+ "unicode/utf8"
1819
1920 "github.com/binance/binance-connector-go/common/common"
2021)
@@ -31,10 +32,10 @@ func (m mockMappedNullable) ToMap() (map[string]interface{}, error) {
3132
3233func TestParameterAddToHeaderOrQuery_BasicTypes (t * testing.T ) {
3334 tests := []struct {
34- name string
35- obj interface {}
35+ name string
36+ obj interface {}
3637 expectedValue string
37- expectedKey string
38+ expectedKey string
3839 collectionType string
3940 }{
4041 {"int" , 42 , "42" , "intKey" , "" },
@@ -588,7 +589,7 @@ func TestPrepareRequest_WithJSONBody(t *testing.T) {
588589 cfg := & common.ConfigurationRestAPI {}
589590 body := struct {
590591 Key1 string `json:"key1"`
591- Key2 int `json:"key2"`
592+ Key2 int `json:"key2"`
592593 }{
593594 Key1 : "value1" ,
594595 Key2 : 123 ,
@@ -640,3 +641,58 @@ func TestPrepareRequest_WithQueryAndBody(t *testing.T) {
640641 t .Errorf ("Expected Content-Type header to be set" )
641642 }
642643}
644+
645+ func TestGenerateUUID (t * testing.T ) {
646+ t .Run ("returns non-empty string" , func (t * testing.T ) {
647+ uuid := common .GenerateUUID ()
648+ if len (uuid ) == 0 {
649+ t .Error ("GenerateUUID() returned empty string" )
650+ }
651+ })
652+
653+ t .Run ("returns valid UTF-8 string" , func (t * testing.T ) {
654+ uuid := common .GenerateUUID ()
655+ if ! utf8 .ValidString (uuid ) {
656+ t .Error ("GenerateUUID() returned invalid UTF-8 string" )
657+ }
658+ })
659+
660+ t .Run ("returns string of expected length" , func (t * testing.T ) {
661+ uuid := common .GenerateUUID ()
662+
663+ if len (uuid ) != 36 {
664+ t .Errorf ("GenerateUUID() returned string of length %d, expected 36" , len (uuid ))
665+ }
666+ })
667+
668+ t .Run ("returns different values on subsequent calls" , func (t * testing.T ) {
669+ first := common .GenerateUUID ()
670+ second := common .GenerateUUID ()
671+ if first == second {
672+ t .Error ("GenerateUUID() returned same value on subsequent calls" )
673+ }
674+ })
675+ }
676+
677+ func TestGenerateIntUUID (t * testing.T ) {
678+ t .Run ("returns a value" , func (t * testing.T ) {
679+ uuid := common .GenerateIntUUID ()
680+ _ = uuid
681+ })
682+
683+ t .Run ("returns different values on subsequent calls" , func (t * testing.T ) {
684+ first := common .GenerateIntUUID ()
685+ second := common .GenerateIntUUID ()
686+ if first == second {
687+ t .Error ("GenerateIntUUID() returned same value on subsequent calls" )
688+ }
689+ })
690+
691+ t .Run ("returns value within int32 range" , func (t * testing.T ) {
692+ uuid := common .GenerateIntUUID ()
693+
694+ if uuid < - 2147483648 || uuid > 2147483647 {
695+ t .Errorf ("GenerateIntUUID() returned value %d outside int32 range" , uuid )
696+ }
697+ })
698+ }
0 commit comments