@@ -103,3 +103,63 @@ func TestRecordAttributes(t *testing.T) {
103
103
}
104
104
})
105
105
}
106
+
107
+ func TestRecordAllocationLimits (t * testing.T ) {
108
+ const runs = 5
109
+
110
+ // Assign testing results to external scope so the compiler doesn't
111
+ // optimize away the testing statements.
112
+ var (
113
+ tStamp time.Time
114
+ sev log.Severity
115
+ text string
116
+ body log.Value
117
+ n int
118
+ attr log.KeyValue
119
+ )
120
+
121
+ assert .Equal (t , 0.0 , testing .AllocsPerRun (runs , func () {
122
+ var r log.Record
123
+ r .SetTimestamp (y2k )
124
+ tStamp = r .Timestamp ()
125
+ }), "Timestamp" )
126
+
127
+ assert .Equal (t , 0.0 , testing .AllocsPerRun (runs , func () {
128
+ var r log.Record
129
+ r .SetObservedTimestamp (y2k )
130
+ tStamp = r .ObservedTimestamp ()
131
+ }), "ObservedTimestamp" )
132
+
133
+ assert .Equal (t , 0.0 , testing .AllocsPerRun (runs , func () {
134
+ var r log.Record
135
+ r .SetSeverity (log .SeverityDebug )
136
+ sev = r .Severity ()
137
+ }), "Severity" )
138
+
139
+ assert .Equal (t , 0.0 , testing .AllocsPerRun (runs , func () {
140
+ var r log.Record
141
+ r .SetSeverityText ("severity text" )
142
+ text = r .SeverityText ()
143
+ }), "SeverityText" )
144
+
145
+ bodyVal := log .BoolValue (true )
146
+ assert .Equal (t , 0.0 , testing .AllocsPerRun (runs , func () {
147
+ var r log.Record
148
+ r .SetBody (bodyVal )
149
+ body = r .Body ()
150
+ }), "Body" )
151
+
152
+ attrVal := []log.KeyValue {log .Bool ("k" , true ), log .Int ("i" , 1 )}
153
+ assert .Equal (t , 0.0 , testing .AllocsPerRun (runs , func () {
154
+ var r log.Record
155
+ r .AddAttributes (attrVal ... )
156
+ n = r .AttributesLen ()
157
+ r .WalkAttributes (func (kv log.KeyValue ) bool {
158
+ attr = kv
159
+ return true
160
+ })
161
+ }), "Attributes" )
162
+
163
+ // Convince the linter these values are used.
164
+ _ , _ , _ , _ , _ , _ = tStamp , sev , text , body , n , attr
165
+ }
0 commit comments