-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschematizedproto_deprecated_test.go
107 lines (103 loc) · 2.37 KB
/
schematizedproto_deprecated_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
102
103
104
105
106
107
package zfmt
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
example2 "github.com/zillow/zfmt/testdata/example"
)
func TestSchematizedProtoDeprecatedFormatter_Marshall(t *testing.T) {
type fields struct {
protobufFormatter ProtobufBase64Formatter
SchemaID int
}
type args struct {
v any
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "accept reference type of an proto object, default formatter should be useful",
fields: fields{},
args: args{
v: &example2.ExampleDef{
Allowed: "!23",
Disallowed: 7,
},
},
wantErr: false,
},
{
name: "accept reference type of an proto object, with avro formatter and schemaID",
fields: fields{
protobufFormatter: ProtobufBase64Formatter{},
SchemaID: 99,
},
args: args{
v: &example2.ExampleDef{
Allowed: "!23",
Disallowed: 7,
},
},
wantErr: false,
},
{
name: "do not accept value type of a proto object",
fields: fields{
protobufFormatter: ProtobufBase64Formatter{},
SchemaID: 99,
},
args: args{
v: example2.ExampleDef{
Allowed: "!23",
Disallowed: 7,
},
},
wantErr: true,
},
{
name: "do not accept random type",
fields: fields{
protobufFormatter: ProtobufBase64Formatter{},
SchemaID: 99,
},
args: args{v: "what?"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &SchematizedProtoFormatterDeprecated{
formatter: tt.fields.protobufFormatter,
SchemaID: tt.fields.SchemaID,
}
_, err := p.Marshall(tt.args.v)
if (err != nil) != tt.wantErr {
t.Errorf("SchematizedProtoFormatter.Marshall() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
func TestSchematizedProtoDeprecatedFormmater_Unmarshall(t *testing.T) {
fmtter := SchematizedProtoFormatterDeprecated{
formatter: ProtobufBase64Formatter{},
SchemaID: 123,
}
expected := example2.ExampleDef{Allowed: "1243", Disallowed: 987}
b, err := fmtter.Marshall(&expected)
if err != nil {
t.Fatal(err)
}
reslt := example2.ExampleDef{}
if err := fmtter.Unmarshal(b, &reslt); err != nil {
t.Fatal(err)
}
diff := cmp.Diff(&reslt, &expected, cmpopts.IgnoreUnexported(example2.ExampleDef{}))
if diff != "" {
t.Fatal(diff)
}
}