-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflatuuid_test.go
50 lines (38 loc) · 1.41 KB
/
flatuuid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package flatuuid_test
import (
"strings"
"testing"
"github.com/ixalender/flatuuid"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func Test_Compact(t *testing.T) {
testUUID := uuid.NewString()
flatUUID, err := flatuuid.Compact(testUUID)
assert.Nil(t, err)
expectedUUID := strings.ReplaceAll(testUUID, "-", "")
assert.Equal(t, expectedUUID, flatUUID)
_, err = flatuuid.Compact("")
assert.NotNil(t, err)
assert.True(t, len(err.Error()) > 0)
_, err = flatuuid.Compact("12345")
assert.NotNil(t, err)
rfc4122UUID := "urn:uuid:f47ac10b-58cc-4372-0567-0e02b2c3d479"
flatUUID, err = flatuuid.Compact(rfc4122UUID)
expectedUUID = strings.Replace(strings.ReplaceAll(rfc4122UUID, "-", ""), "urn:uuid:", "", 1)
assert.Nil(t, err)
assert.Equal(t, expectedUUID, flatUUID)
microsoftGUIDUpper := "{78B83322-84F6-46E8-A0BE-238FB5703A09}"
flatUUID, err = flatuuid.Compact(microsoftGUIDUpper)
expectedUUIDLower := strings.ToLower(strings.Trim(strings.ReplaceAll(microsoftGUIDUpper, "-", ""), "{}"))
assert.Nil(t, err)
assert.Equal(t, expectedUUIDLower, flatUUID)
flattenUUID := "78b8332284f646e8a0be238fb5703a09"
flatUUID, err = flatuuid.Compact(flattenUUID)
assert.Nil(t, err)
assert.Equal(t, flattenUUID, flatUUID)
flattenUpperUUID := "78B8332284F646E8A0BE238FB5703A09"
flatUUID, err = flatuuid.Compact(flattenUpperUUID)
assert.Nil(t, err)
assert.Equal(t, strings.ToLower(flattenUpperUUID), flatUUID)
}