forked from linkedin/goavro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
salsify_uuid_test.go
72 lines (58 loc) · 1.84 KB
/
salsify_uuid_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package goavro
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSalsifyCompressedUUIDTextualFromNative(t *testing.T) {
source := []byte("\xDB\x81P\x12X[K\xEC\x96\x1AR\xC4\x1E\x1D\xE0W")
buf := make([]byte, 0)
buf, err := salsifyCompressedUUIDTextualFromNative(buf, source)
assert.NoError(t, err)
assert.Equal(t, buf, []byte("\"s-db815012-585b-4bec-961a-52c41e1de057\""))
}
func TestSalsifyCompressedUUIDNativeFromTextual(t *testing.T) {
source := []byte("\"s-db815012-585b-4bec-961a-52c41e1de057\"")
native, _, err := salsifyCompressedUUIDNativeFromTextual(source)
assert.NoError(t, err)
assert.Equal(t, native, []byte("\xDB\x81P\x12X[K\xEC\x96\x1AR\xC4\x1E\x1D\xE0W"))
}
func TestSalsifyCompressedEndToEnd(t *testing.T) {
schema := `{"type":"fixed","name":"salsify_uuid_binary","namespace":"com.salsify","size":16}`
rawBinary, err := os.ReadFile("fixtures/salsify_uuid_binary.avro")
if err != nil {
t.Fatal(err)
}
codec, err := NewCodec(schema)
if err != nil {
t.Fatal(err)
}
fromNative, _, err := codec.NativeFromBinary(rawBinary)
if err != nil {
t.Fatal(err)
}
fromTextual, err := codec.TextualFromNative(nil, fromNative)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, fromTextual, []byte("\"s-e895a664-e7e5-43e6-9f5f-2320787ff569\""))
toNative, _, err := codec.NativeFromTextual(fromTextual)
if err != nil {
t.Fatal(err)
}
toBinary, err := codec.BinaryFromNative(nil, toNative)
if err != nil {
t.Fatal(err)
}
// Go decoding adds a non-breaking space 0xA0 at the end.
assert.Equal(t, toBinary[:16], rawBinary[:16])
backUpNative, _, err := codec.NativeFromBinary(toBinary)
if err != nil {
t.Fatal(err)
}
backUpTextual, err := codec.textualFromNative(nil, backUpNative)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, backUpTextual, []byte("\"s-e895a664-e7e5-43e6-9f5f-2320787ff569\""))
}