Debian Codegraph @

pdata/internal/generated_proto_exponentialhistogramdatapoint_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 // Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT.
5 // To regenerate this file run "make genpdata".
6
7 package internal
8
9 import (
10 "strconv"
11 "testing"
12
13 "github.com/stretchr/testify/assert"
14 "github.com/stretchr/testify/require"
15 gootlpmetrics "go.opentelemetry.io/proto/slim/otlp/metrics/v1"
16 "google.golang.org/protobuf/proto"
17
18 "go.opentelemetry.io/collector/featuregate"
19 "go.opentelemetry.io/collector/pdata/internal/json"
20 )
21
22 func TestCopyExponentialHistogramDataPoint(t *testing.T) {
23 for name, src := range genTestEncodingValuesExponentialHistogramDataPoint() {
24 for _, pooling := range []bool{true, false} {
25 t.Run(name+"/Pooling="+strconv.FormatBool(pooling), func(t *testing.T) {
26 prevPooling := UseProtoPooling.IsEnabled()
27 require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
28 defer func() {
29 require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), prevPooling))
30 }()
31
32 dest := NewExponentialHistogramDataPoint()
33 CopyExponentialHistogramDataPoint(dest, src)
34 assert.Equal(t, src, dest)
35 CopyExponentialHistogramDataPoint(dest, dest)
36 assert.Equal(t, src, dest)
37 })
38 }
39 }
40 }
41
42 func TestCopyExponentialHistogramDataPointSlice(t *testing.T) {
43 src := []ExponentialHistogramDataPoint{}
44 dest := []ExponentialHistogramDataPoint{}
45 // Test CopyTo empty
46 dest = CopyExponentialHistogramDataPointSlice(dest, src)
47 assert.Equal(t, []ExponentialHistogramDataPoint{}, dest)
48
49 // Test CopyTo larger slice
50 src = GenTestExponentialHistogramDataPointSlice()
51 dest = CopyExponentialHistogramDataPointSlice(dest, src)
52 assert.Equal(t, GenTestExponentialHistogramDataPointSlice(), dest)
53
54 // Test CopyTo same size slice
55 dest = CopyExponentialHistogramDataPointSlice(dest, src)
56 assert.Equal(t, GenTestExponentialHistogramDataPointSlice(), dest)
57
58 // Test CopyTo smaller size slice
59 dest = CopyExponentialHistogramDataPointSlice(dest, []ExponentialHistogramDataPoint{})
60 assert.Len(t, dest, 0)
61
62 // Test CopyTo larger slice with enough capacity
63 dest = CopyExponentialHistogramDataPointSlice(dest, src)
64 assert.Equal(t, GenTestExponentialHistogramDataPointSlice(), dest)
65 }
66
67 func TestCopyExponentialHistogramDataPointPtrSlice(t *testing.T) {
68 src := []*ExponentialHistogramDataPoint{}
69 dest := []*ExponentialHistogramDataPoint{}
70 // Test CopyTo empty
71 dest = CopyExponentialHistogramDataPointPtrSlice(dest, src)
72 assert.Equal(t, []*ExponentialHistogramDataPoint{}, dest)
73
74 // Test CopyTo larger slice
75 src = GenTestExponentialHistogramDataPointPtrSlice()
76 dest = CopyExponentialHistogramDataPointPtrSlice(dest, src)
77 assert.Equal(t, GenTestExponentialHistogramDataPointPtrSlice(), dest)
78
79 // Test CopyTo same size slice
80 dest = CopyExponentialHistogramDataPointPtrSlice(dest, src)
81 assert.Equal(t, GenTestExponentialHistogramDataPointPtrSlice(), dest)
82
83 // Test CopyTo smaller size slice
84 dest = CopyExponentialHistogramDataPointPtrSlice(dest, []*ExponentialHistogramDataPoint{})
85 assert.Len(t, dest, 0)
86
87 // Test CopyTo larger slice with enough capacity
88 dest = CopyExponentialHistogramDataPointPtrSlice(dest, src)
89 assert.Equal(t, GenTestExponentialHistogramDataPointPtrSlice(), dest)
90 }
91
92 func TestMarshalAndUnmarshalJSONExponentialHistogramDataPointUnknown(t *testing.T) {
93 iter := json.BorrowIterator([]byte(`{"unknown": "string"}`))
94 defer json.ReturnIterator(iter)
95 dest := NewExponentialHistogramDataPoint()
96 dest.UnmarshalJSON(iter)
97 require.NoError(t, iter.Error())
98 assert.Equal(t, NewExponentialHistogramDataPoint(), dest)
99 }
100
101 func TestMarshalAndUnmarshalJSONExponentialHistogramDataPoint(t *testing.T) {
102 for name, src := range genTestEncodingValuesExponentialHistogramDataPoint() {
103 for _, pooling := range []bool{true, false} {
104 t.Run(name+"/Pooling="+strconv.FormatBool(pooling), func(t *testing.T) {
105 prevPooling := UseProtoPooling.IsEnabled()
106 require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
107 defer func() {
108 require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), prevPooling))
109 }()
110
111 stream := json.BorrowStream(nil)
112 defer json.ReturnStream(stream)
113 src.MarshalJSON(stream)
114 require.NoError(t, stream.Error())
115
116 iter := json.BorrowIterator(stream.Buffer())
117 defer json.ReturnIterator(iter)
118 dest := NewExponentialHistogramDataPoint()
119 dest.UnmarshalJSON(iter)
120 require.NoError(t, iter.Error())
121
122 assert.Equal(t, src, dest)
123 DeleteExponentialHistogramDataPoint(dest, true)
124 })
125 }
126 }
127 }
128
129 func TestMarshalAndUnmarshalProtoExponentialHistogramDataPointFailing(t *testing.T) {
130 for name, buf := range genTestFailingUnmarshalProtoValuesExponentialHistogramDataPoint() {
131 t.Run(name, func(t *testing.T) {
132 dest := NewExponentialHistogramDataPoint()
133 require.Error(t, dest.UnmarshalProto(buf))
134 })
135 }
136 }
137
138 func TestMarshalAndUnmarshalProtoExponentialHistogramDataPointUnknown(t *testing.T) {
139 dest := NewExponentialHistogramDataPoint()
140 // message Test { required int64 field = 1313; } encoding { "field": "1234" }
141 require.NoError(t, dest.UnmarshalProto([]byte{0x88, 0x52, 0xD2, 0x09}))
142 assert.Equal(t, NewExponentialHistogramDataPoint(), dest)
143 }
144
145 func TestMarshalAndUnmarshalProtoExponentialHistogramDataPoint(t *testing.T) {
146 for name, src := range genTestEncodingValuesExponentialHistogramDataPoint() {
147 for _, pooling := range []bool{true, false} {
148 t.Run(name+"/Pooling="+strconv.FormatBool(pooling), func(t *testing.T) {
149 prevPooling := UseProtoPooling.IsEnabled()
150 require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
151 defer func() {
152 require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), prevPooling))
153 }()
154
155 buf := make([]byte, src.SizeProto())
156 gotSize := src.MarshalProto(buf)
157 assert.Equal(t, len(buf), gotSize)
158
159 dest := NewExponentialHistogramDataPoint()
160 require.NoError(t, dest.UnmarshalProto(buf))
161
162 assert.Equal(t, src, dest)
163 DeleteExponentialHistogramDataPoint(dest, true)
164 })
165 }
166 }
167 }
168
169 func TestMarshalAndUnmarshalProtoViaProtobufExponentialHistogramDataPoint(t *testing.T) {
170 for name, src := range genTestEncodingValuesExponentialHistogramDataPoint() {
171 t.Run(name, func(t *testing.T) {
172 buf := make([]byte, src.SizeProto())
173 gotSize := src.MarshalProto(buf)
174 assert.Equal(t, len(buf), gotSize)
175
176 goDest := &gootlpmetrics.ExponentialHistogramDataPoint{}
177 require.NoError(t, proto.Unmarshal(buf, goDest))
178
179 goBuf, err := proto.Marshal(goDest)
180 require.NoError(t, err)
181
182 dest := NewExponentialHistogramDataPoint()
183 require.NoError(t, dest.UnmarshalProto(goBuf))
184 assert.Equal(t, src, dest)
185 })
186 }
187 }
188
189 func genTestFailingUnmarshalProtoValuesExponentialHistogramDataPoint() map[string][]byte {
190 return map[string][]byte{
191 "invalid_field": {0x02},
192 "Attributes/wrong_wire_type": {0xc},
193 "Attributes/missing_value": {0xa},
194 "StartTimeUnixNano/wrong_wire_type": {0x14},
195 "StartTimeUnixNano/missing_value": {0x11},
196 "TimeUnixNano/wrong_wire_type": {0x1c},
197 "TimeUnixNano/missing_value": {0x19},
198 "Count/wrong_wire_type": {0x24},
199 "Count/missing_value": {0x21},
200 "Sum/wrong_wire_type": {0x2c},
201 "Sum/missing_value": {0x29},
202 "Scale/wrong_wire_type": {0x34},
203 "Scale/missing_value": {0x30},
204 "ZeroCount/wrong_wire_type": {0x3c},
205 "ZeroCount/missing_value": {0x39},
206 "Positive/wrong_wire_type": {0x44},
207 "Positive/missing_value": {0x42},
208 "Negative/wrong_wire_type": {0x4c},
209 "Negative/missing_value": {0x4a},
210 "Flags/wrong_wire_type": {0x54},
211 "Flags/missing_value": {0x50},
212 "Exemplars/wrong_wire_type": {0x5c},
213 "Exemplars/missing_value": {0x5a},
214 "Min/wrong_wire_type": {0x64},
215 "Min/missing_value": {0x61},
216 "Max/wrong_wire_type": {0x6c},
217 "Max/missing_value": {0x69},
218 "ZeroThreshold/wrong_wire_type": {0x74},
219 "ZeroThreshold/missing_value": {0x71},
220 }
221 }
222
223 func genTestEncodingValuesExponentialHistogramDataPoint() map[string]*ExponentialHistogramDataPoint {
224 return map[string]*ExponentialHistogramDataPoint{
225 "empty": NewExponentialHistogramDataPoint(),
226 "Attributes/test": {Attributes: []KeyValue{{}, *GenTestKeyValue()}},
227 "StartTimeUnixNano/test": {StartTimeUnixNano: uint64(13)},
228 "TimeUnixNano/test": {TimeUnixNano: uint64(13)},
229 "Count/test": {Count: uint64(13)}, "Sum/default": {Sum_: &ExponentialHistogramDataPoint_Sum{Sum: float64(0)}},
230 "Sum/test": {Sum_: &ExponentialHistogramDataPoint_Sum{Sum: float64(3.1415926)}},
231 "Scale/test": {Scale: int32(13)},
232 "ZeroCount/test": {ZeroCount: uint64(13)},
233 "Positive/test": {Positive: *GenTestExponentialHistogramDataPointBuckets()},
234 "Negative/test": {Negative: *GenTestExponentialHistogramDataPointBuckets()},
235 "Flags/test": {Flags: uint32(13)},
236 "Exemplars/test": {Exemplars: []Exemplar{{}, *GenTestExemplar()}}, "Min/default": {Min_: &ExponentialHistogramDataPoint_Min{Min: float64(0)}},
237 "Min/test": {Min_: &ExponentialHistogramDataPoint_Min{Min: float64(3.1415926)}}, "Max/default": {Max_: &ExponentialHistogramDataPoint_Max{Max: float64(0)}},
238 "Max/test": {Max_: &ExponentialHistogramDataPoint_Max{Max: float64(3.1415926)}},
239 "ZeroThreshold/test": {ZeroThreshold: float64(3.1415926)},
240 }
241 }