@@ -22,6 +22,7 @@ package protobuf
22
22
23
23
import (
24
24
"bytes"
25
+ "encoding/binary"
25
26
"io"
26
27
"strings"
27
28
"testing"
@@ -103,7 +104,7 @@ func TestUnaggregatedIteratorDecodeBatchTimerWithMetadatas(t *testing.T) {
103
104
enc := NewUnaggregatedEncoder (NewUnaggregatedOptions ())
104
105
for _ , input := range inputs {
105
106
require .NoError (t , enc .EncodeMessage (encoding.UnaggregatedMessageUnion {
106
- Type : encoding .BatchTimerWithMetadatasType ,
107
+ Type : encoding .BatchTimerWithMetadatasType ,
107
108
BatchTimerWithMetadatas : input ,
108
109
}))
109
110
}
@@ -195,7 +196,7 @@ func TestUnaggregatedIteratorDecodeForwardedMetricWithMetadata(t *testing.T) {
195
196
enc := NewUnaggregatedEncoder (NewUnaggregatedOptions ())
196
197
for _ , input := range inputs {
197
198
require .NoError (t , enc .EncodeMessage (encoding.UnaggregatedMessageUnion {
198
- Type : encoding .ForwardedMetricWithMetadataType ,
199
+ Type : encoding .ForwardedMetricWithMetadataType ,
199
200
ForwardedMetricWithMetadata : input ,
200
201
}))
201
202
}
@@ -286,7 +287,7 @@ func TestUnaggregatedIteratorDecodeTimedMetricWithMetadata(t *testing.T) {
286
287
enc := NewUnaggregatedEncoder (NewUnaggregatedOptions ())
287
288
for _ , input := range inputs {
288
289
require .NoError (t , enc .EncodeMessage (encoding.UnaggregatedMessageUnion {
289
- Type : encoding .TimedMetricWithMetadataType ,
290
+ Type : encoding .TimedMetricWithMetadataType ,
290
291
TimedMetricWithMetadata : input ,
291
292
}))
292
293
}
@@ -406,7 +407,7 @@ func TestUnaggregatedIteratorDecodeStress(t *testing.T) {
406
407
}
407
408
case unaggregated.BatchTimerWithMetadatas :
408
409
msg = encoding.UnaggregatedMessageUnion {
409
- Type : encoding .BatchTimerWithMetadatasType ,
410
+ Type : encoding .BatchTimerWithMetadatasType ,
410
411
BatchTimerWithMetadatas : input ,
411
412
}
412
413
case unaggregated.GaugeWithMetadatas :
@@ -416,17 +417,17 @@ func TestUnaggregatedIteratorDecodeStress(t *testing.T) {
416
417
}
417
418
case aggregated.ForwardedMetricWithMetadata :
418
419
msg = encoding.UnaggregatedMessageUnion {
419
- Type : encoding .ForwardedMetricWithMetadataType ,
420
+ Type : encoding .ForwardedMetricWithMetadataType ,
420
421
ForwardedMetricWithMetadata : input ,
421
422
}
422
423
case aggregated.TimedMetricWithMetadata :
423
424
msg = encoding.UnaggregatedMessageUnion {
424
- Type : encoding .TimedMetricWithMetadataType ,
425
+ Type : encoding .TimedMetricWithMetadataType ,
425
426
TimedMetricWithMetadata : input ,
426
427
}
427
428
case aggregated.PassthroughMetricWithMetadata :
428
429
msg = encoding.UnaggregatedMessageUnion {
429
- Type : encoding .PassthroughMetricWithMetadataType ,
430
+ Type : encoding .PassthroughMetricWithMetadataType ,
430
431
PassthroughMetricWithMetadata : input ,
431
432
}
432
433
default :
@@ -554,3 +555,20 @@ func TestUnaggregatedIteratorNextOnClose(t *testing.T) {
554
555
// Verify that closing a second time is a no op.
555
556
it .Close ()
556
557
}
558
+
559
+ func TestUnaggregatedIteratorNextOnInvalid (t * testing.T ) {
560
+ buf := make ([]byte , 32 )
561
+ binary .PutVarint (buf , 0 )
562
+ stream := bytes .NewReader (buf )
563
+
564
+ it := NewUnaggregatedIterator (stream , NewUnaggregatedOptions ())
565
+ require .False (t , it .Next ())
566
+ require .False (t , it .Next ())
567
+
568
+ buf = make ([]byte , 32 )
569
+ binary .PutVarint (buf , - 1234 )
570
+ stream = bytes .NewReader (buf )
571
+ it = NewUnaggregatedIterator (stream , NewUnaggregatedOptions ())
572
+ require .False (t , it .Next ())
573
+ require .False (t , it .Next ())
574
+ }
0 commit comments