@@ -540,13 +540,14 @@ func TestAttributeMapWithEmpty(t *testing.T) {
540
540
}
541
541
542
542
func TestAttributeMapIterationNil (t * testing.T ) {
543
- NewAttributeMap ().ForEach (func (k string , v AttributeValue ) {
543
+ NewAttributeMap ().Range (func (k string , v AttributeValue ) bool {
544
544
// Fail if any element is returned
545
545
t .Fail ()
546
+ return true
546
547
})
547
548
}
548
549
549
- func TestAttributeMap_ForEach (t * testing.T ) {
550
+ func TestAttributeMap_Range (t * testing.T ) {
550
551
rawMap := map [string ]AttributeValue {
551
552
"k_string" : NewAttributeValueString ("123" ),
552
553
"k_int" : NewAttributeValueInt (123 ),
@@ -555,11 +556,19 @@ func TestAttributeMap_ForEach(t *testing.T) {
555
556
"k_null" : NewAttributeValueNull (),
556
557
}
557
558
am := NewAttributeMap ().InitFromMap (rawMap )
558
- assert .EqualValues (t , 5 , am .Len ())
559
+ assert .Equal (t , 5 , am .Len ())
559
560
560
- am .ForEach (func (k string , v AttributeValue ) {
561
+ calls := 0
562
+ am .Range (func (k string , v AttributeValue ) bool {
563
+ calls ++
564
+ return false
565
+ })
566
+ assert .Equal (t , 1 , calls )
567
+
568
+ am .Range (func (k string , v AttributeValue ) bool {
561
569
assert .True (t , v .Equal (rawMap [k ]))
562
570
delete (rawMap , k )
571
+ return true
563
572
})
564
573
assert .EqualValues (t , 0 , len (rawMap ))
565
574
}
@@ -837,20 +846,29 @@ func TestStringMap(t *testing.T) {
837
846
}
838
847
839
848
func TestStringMapIterationNil (t * testing.T ) {
840
- NewStringMap ().ForEach (func (k string , v string ) {
849
+ NewStringMap ().Range (func (k string , v string ) bool {
841
850
// Fail if any element is returned
842
851
t .Fail ()
852
+ return true
843
853
})
844
854
}
845
855
846
- func TestStringMap_ForEach (t * testing.T ) {
856
+ func TestStringMap_Range (t * testing.T ) {
847
857
rawMap := map [string ]string {"k0" : "v0" , "k1" : "v1" , "k2" : "v2" }
848
858
sm := NewStringMap ().InitFromMap (rawMap )
849
859
assert .EqualValues (t , 3 , sm .Len ())
850
860
851
- sm .ForEach (func (k string , v string ) {
861
+ calls := 0
862
+ sm .Range (func (k string , v string ) bool {
863
+ calls ++
864
+ return false
865
+ })
866
+ assert .Equal (t , 1 , calls )
867
+
868
+ sm .Range (func (k string , v string ) bool {
852
869
assert .EqualValues (t , rawMap [k ], v )
853
870
delete (rawMap , k )
871
+ return true
854
872
})
855
873
assert .EqualValues (t , 0 , len (rawMap ))
856
874
}
@@ -949,7 +967,7 @@ func BenchmarkAttributeValue_SetIntVal(b *testing.B) {
949
967
}
950
968
}
951
969
952
- func BenchmarkAttributeMap_ForEach (b * testing.B ) {
970
+ func BenchmarkAttributeMap_Range (b * testing.B ) {
953
971
const numElements = 20
954
972
rawOrig := make ([]otlpcommon.KeyValue , numElements )
955
973
for i := 0 ; i < numElements ; i ++ {
@@ -964,8 +982,9 @@ func BenchmarkAttributeMap_ForEach(b *testing.B) {
964
982
b .ResetTimer ()
965
983
for n := 0 ; n < b .N ; n ++ {
966
984
numEls := 0
967
- am .ForEach (func (k string , v AttributeValue ) {
985
+ am .Range (func (k string , v AttributeValue ) bool {
968
986
numEls ++
987
+ return true
969
988
})
970
989
if numEls != numElements {
971
990
b .Fail ()
@@ -995,7 +1014,7 @@ func BenchmarkAttributeMap_RangeOverMap(b *testing.B) {
995
1014
}
996
1015
}
997
1016
998
- func BenchmarkStringMap_ForEach (b * testing.B ) {
1017
+ func BenchmarkStringMap_Range (b * testing.B ) {
999
1018
const numElements = 20
1000
1019
rawOrig := make ([]otlpcommon.StringKeyValue , numElements )
1001
1020
for i := 0 ; i < numElements ; i ++ {
@@ -1010,8 +1029,9 @@ func BenchmarkStringMap_ForEach(b *testing.B) {
1010
1029
b .ResetTimer ()
1011
1030
for n := 0 ; n < b .N ; n ++ {
1012
1031
numEls := 0
1013
- sm .ForEach (func (s string , value string ) {
1032
+ sm .Range (func (s string , value string ) bool {
1014
1033
numEls ++
1034
+ return true
1015
1035
})
1016
1036
if numEls != numElements {
1017
1037
b .Fail ()
0 commit comments