-
Notifications
You must be signed in to change notification settings - Fork 2
/
cache_schema_registry_test.go
101 lines (82 loc) · 1.67 KB
/
cache_schema_registry_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package avrostry
import "testing"
func TestGetByID(t *testing.T) {
cache := NewCacheSchemaRegistry()
cache.SetBySubjectSquema("subject", "schema", 1)
schema, found := cache.GetByID(1)
if schema != "schema" {
t.Fail()
}
if !found {
t.Fail()
}
}
func TestGetIDBySubjectAndSquemaSimpleCase(t *testing.T) {
cache := NewCacheSchemaRegistry()
cache.SetBySubjectSquema("subject", "schema", 1)
id, found := cache.GetIDBySubjectAndSquema("subject", "schema")
if id != 1 {
t.Fail()
}
if !found {
t.Fail()
}
}
func TestGetIDBySubjectAndSquemaForNewSchema(t *testing.T) {
cache := NewCacheSchemaRegistry()
event1 := event1{}
cache.SetBySubjectSquema(event1.Subject(), event1.AvroSchema(), 1)
event2 := event2{}
id, found := cache.GetIDBySubjectAndSquema(event2.Subject(), event2.AvroSchema())
if id == 1 {
t.Fail()
}
if found {
t.Fail()
}
}
type event1 struct {
}
func (event1) AvroSchema() string {
return `{
"type": "record",
"name": "name",
"namespace": "namespace",
"fields": [
{"name": "uuid", "type": "string"}
]
}`
}
func (event1) Subject() string {
return "name"
}
func (event1) ToStringMap() map[string]interface{} {
var m map[string]interface{}
return m
}
func (event1) ID() string {
return "id"
}
type event2 struct {
}
func (event2) AvroSchema() string {
return `{
"type": "record",
"name": "name",
"namespace": "namespace.booking",
"fields": [
{"name": "uuid", "type": "string"},
{"name": "name", "type": "string"}
]
}`
}
func (event2) Subject() string {
return "name"
}
func (event2) ToStringMap() map[string]interface{} {
var m map[string]interface{}
return m
}
func (event2) ID() string {
return "id"
}