Atlas › Test
TestDecodeHistories
Exact test identity: go.temporal.io/server/common/codec/TestJSONPBEncoderSuite/TestDecodeHistories
- Package
go.temporal.io/server/common/codec
- Suite / test hierarchy
TestJSONPBEncoderSuite/TestDecodeHistories
- Test
TestDecodeHistories
- Introduced at
- TestDecodeHistories, TestDecodeOldHistories Frontier kind: Test frontier
- Covered ranges
- 12
- Covered lines
- 39
- Covered files
- 2
Co-introduced tests
1 other test enter at the same concept.
Covered source
Expand a file to inspect source; the > gutter marks covered lines.
go.temporal.io/server/common/codec/jsonpb.go 31 covered LOC · 9 ranges
Open complete file
23
24
// NewJSONPBEncoder creates a new JSONPBEncoder.
25
>
func NewJSONPBEncoder() JSONPBEncoder {
jsonpb.go
26
>
return JSONPBEncoder{}
27
>
}
28
29
// NewJSONPBIndentEncoder creates a new JSONPBEncoder with indent.
74
75
// Decode History slice from bytes.
76
>
func (e *JSONPBEncoder) DecodeHistories(data []byte) ([]*historypb.History, error) {
jsonpb.go
77
>
var histories []*historypb.History
78
>
err := e.DecodeSlice(
79
>
data,
80
>
func() proto.Message {
81
>
history := &historypb.History{}
82
>
histories = append(histories, history)
83
>
return history
84
>
})
85
87
}
88
114
func (e *JSONPBEncoder) DecodeSlice(
115
data []byte,
116
>
constructor func() proto.Message) error {
jsonpb.go
117
>
118
>
dec := json.NewDecoder(bytes.NewReader(data))
119
>
120
>
tok, err := dec.Token()
121
>
if err != nil {
122
return err
123
}
124
>
if delim, ok := tok.(json.Delim); !ok || delim != '[' {
jsonpb.go
125
return fmt.Errorf("invalid json: expected [ but found %v", tok)
126
}
128
// We need DiscardUnknown here as the history json may have been written by a
129
// different proto revision
130
>
unmarshaller := temporalproto.CustomJSONUnmarshalOptions{
jsonpb.go
131
>
DiscardUnknown: true,
132
>
}
133
>
134
>
var buf json.RawMessage
135
>
for dec.More() {
136
>
if err := dec.Decode(&buf); err != nil {
137
return err
138
}
140
>
if err := unmarshaller.Unmarshal([]byte(buf), pb); err != nil {
141
return err
142
}
144
}
145
147
}
go.temporal.io/server/common/testing/protoassert/assert.go 8 covered LOC · 3 ranges
Open complete file
49
// generic parameters and slice casting (say from []historyEvent) to
50
// []proto.Message is impossible
51
>
func ProtoSliceEqual[T proto.Message](t assert.TestingT, a []T, b []T) bool {
assert.go
52
>
if th, ok := t.(helper); ok {
53
>
th.Helper()
54
>
}
55
>
if len(a) != len(b) {
56
return false
57
}
59
>
if diff := cmp.Diff(a[i], b[i], protocmp.Transform()); diff != "" {
60
return assert.Fail(t, fmt.Sprintf("Proto mismatch at index %d (-want +got):\n%v", i, diff))
61
}
62
}
63
65
}
66