github.com/kelleygo/clashcore@v1.0.2/common/utils/uuid_test.go (about) 1 package utils 2 3 import ( 4 "github.com/gofrs/uuid/v5" 5 "reflect" 6 "testing" 7 ) 8 9 func TestUUIDMap(t *testing.T) { 10 type args struct { 11 str string 12 } 13 14 tests := []struct { 15 name string 16 args args 17 want uuid.UUID 18 wantErr bool 19 }{ 20 { 21 name: "uuid-test-1", 22 args: args{ 23 str: "82410302-039e-41b6-98b0-d964084b4170", 24 }, 25 want: uuid.FromStringOrNil("82410302-039e-41b6-98b0-d964084b4170"), 26 wantErr: false, 27 }, 28 { 29 name: "uuid-test-2", 30 args: args{ 31 str: "88c502e6-d7eb-4c8e-8259-94cb13d83c77", 32 }, 33 want: uuid.FromStringOrNil("88c502e6-d7eb-4c8e-8259-94cb13d83c77"), 34 wantErr: false, 35 }, 36 { 37 name: "uuid-map-1", 38 args: args{ 39 str: "123456", 40 }, 41 want: uuid.FromStringOrNil("f8598425-92f2-5508-a071-4fc67f9040ac"), 42 wantErr: false, 43 }, 44 // GENERATED BY 'xray uuid -i' 45 { 46 name: "uuid-map-2", 47 args: args{ 48 str: "a9dk23bz0", 49 }, 50 want: uuid.FromStringOrNil("c91481b6-fc0f-5d9e-b166-5ddf07b9c3c5"), 51 wantErr: false, 52 }, 53 { 54 name: "uuid-map-2", 55 args: args{ 56 str: "中文123", 57 }, 58 want: uuid.FromStringOrNil("145c544c-2229-59e5-8dbb-3f33b7610d26"), 59 wantErr: false, 60 }, 61 } 62 for _, tt := range tests { 63 t.Run(tt.name, func(t *testing.T) { 64 got, err := UUIDMap(tt.args.str) 65 if (err != nil) != tt.wantErr { 66 t.Errorf("UUIDMap() error = %v, wantErr %v", err, tt.wantErr) 67 return 68 } 69 if !reflect.DeepEqual(got, tt.want) { 70 t.Errorf("UUIDMap() got = %v, want %v", got, tt.want) 71 } 72 }) 73 } 74 }