@@ -217,26 +217,35 @@ func Test_Entity_EntitiesWithSameMetadataAreSameAs(t *testing.T) {
217217
218218func TestEntity_AddCommonDimension (t * testing.T ) {
219219 tests := []struct {
220- name string
221- commons metric.Dimensions
222- expeceted * Entity
220+ name string
221+ commons metric.Dimensions
222+ expected * Entity
223223 }{
224224 {"empty" , nil , newHostEntity ()},
225225 {"one entry" , metric.Dimensions {"k" : "v" }, & Entity {
226- CommonDimensions : metric.Dimensions {"k" : "v" },
227- Metadata : nil ,
228- Metrics : metric.Metrics {},
229- Inventory : inventory .New (),
230- Events : event.Events {},
231- lock : & sync.Mutex {},
226+ CommonDimensions : Common {
227+ Attributes : map [string ]interface {}{
228+ "k" : "v" ,
229+ },
230+ },
231+ Metadata : nil ,
232+ Metrics : metric.Metrics {},
233+ Inventory : inventory .New (),
234+ Events : event.Events {},
235+ lock : & sync.Mutex {},
232236 }},
233237 {"two entries" , metric.Dimensions {"k1" : "v1" , "k2" : "v2" }, & Entity {
234- CommonDimensions : metric.Dimensions {"k1" : "v1" , "k2" : "v2" },
235- Metadata : nil ,
236- Metrics : metric.Metrics {},
237- Inventory : inventory .New (),
238- Events : event.Events {},
239- lock : & sync.Mutex {},
238+ CommonDimensions : Common {
239+ Attributes : map [string ]interface {}{
240+ "k1" : "v1" ,
241+ "k2" : "v2" ,
242+ },
243+ },
244+ Metadata : nil ,
245+ Metrics : metric.Metrics {},
246+ Inventory : inventory .New (),
247+ Events : event.Events {},
248+ lock : & sync.Mutex {},
240249 }},
241250 }
242251 for _ , tt := range tests {
@@ -247,7 +256,67 @@ func TestEntity_AddCommonDimension(t *testing.T) {
247256 got .AddCommonDimension (k , v )
248257 }
249258
250- assert .Equal (t , tt .expeceted , got )
259+ assert .Equal (t , tt .expected , got )
260+ })
261+ }
262+ }
263+
264+ func TestEntity_AddCommonTimestamp (t * testing.T ) {
265+ asPtr := func (i int64 ) * int64 {
266+ return & i
267+ }
268+ tests := []struct {
269+ name string
270+ timestamp time.Time
271+ expected * Entity
272+ }{
273+ {"one entry" , time .Unix (10000000 , 0 ), & Entity {
274+ CommonDimensions : Common {
275+ Timestamp : asPtr (10000000 ),
276+ },
277+ Metadata : nil ,
278+ Metrics : metric.Metrics {},
279+ Inventory : inventory .New (),
280+ Events : event.Events {},
281+ lock : & sync.Mutex {},
282+ }},
283+ }
284+ for _ , tt := range tests {
285+ t .Run (tt .name , func (t * testing.T ) {
286+ got := newHostEntity ()
287+ got .AddCommonTimestamp (tt .timestamp )
288+ assert .NotNil (t , got .CommonDimensions .Timestamp )
289+ assert .Equal (t , * tt .expected .CommonDimensions .Timestamp , * got .CommonDimensions .Timestamp )
290+ })
291+ }
292+ }
293+
294+ func TestEntity_AddCommonInterval (t * testing.T ) {
295+ asPtr := func (i int64 ) * int64 {
296+ return & i
297+ }
298+ tests := []struct {
299+ name string
300+ interval time.Duration
301+ expected * Entity
302+ }{
303+ {"one entry" , time .Duration (100000000 ), & Entity {
304+ CommonDimensions : Common {
305+ Interval : asPtr (100 ),
306+ },
307+ Metadata : nil ,
308+ Metrics : metric.Metrics {},
309+ Inventory : inventory .New (),
310+ Events : event.Events {},
311+ lock : & sync.Mutex {},
312+ }},
313+ }
314+ for _ , tt := range tests {
315+ t .Run (tt .name , func (t * testing.T ) {
316+ got := newHostEntity ()
317+ got .AddCommonInterval (tt .interval )
318+ assert .NotNil (t , got .CommonDimensions .Interval )
319+ assert .Equal (t , * tt .expected .CommonDimensions .Interval , * got .CommonDimensions .Interval )
251320 })
252321 }
253322}
0 commit comments