1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Robert Pająk
2025-01-22 15:02:47 +01:00
committed by GitHub
parent e108415418
commit 185547c846
7 changed files with 37 additions and 2 deletions
+4
View File
@@ -15,6 +15,10 @@ import (
func AssertRecordEqual(t testing.TB, want, got log.Record) bool {
t.Helper()
if want.EventName() != got.EventName() {
t.Errorf("EventName value is not equal:\nwant: %v\ngot: %v", want.EventName(), got.EventName())
return false
}
if !want.Timestamp().Equal(got.Timestamp()) {
t.Errorf("Timestamp value is not equal:\nwant: %v\ngot: %v", want.Timestamp(), got.Timestamp())
return false
+3 -2
View File
@@ -13,10 +13,11 @@ import (
func TestAssertRecord(t *testing.T) {
r1 := log.Record{}
r2 := log.Record{}
now := time.Now()
AssertRecordEqual(t, r1, r2)
now := time.Now()
r1.SetEventName("my_event")
r2.SetEventName("my_event")
r1.SetTimestamp(now)
r2.SetTimestamp(now)
r1.SetObservedTimestamp(now)
+2
View File
@@ -14,6 +14,7 @@ import (
//
// Do not use RecordFactory to create records in production code.
type RecordFactory struct {
EventName string
Timestamp time.Time
ObservedTimestamp time.Time
Severity log.Severity
@@ -25,6 +26,7 @@ type RecordFactory struct {
// NewRecord returns a log record.
func (b RecordFactory) NewRecord() log.Record {
var record log.Record
record.SetEventName(b.EventName)
record.SetTimestamp(b.Timestamp)
record.SetObservedTimestamp(b.ObservedTimestamp)
record.SetSeverity(b.Severity)
+3
View File
@@ -15,6 +15,7 @@ import (
func TestRecordFactory(t *testing.T) {
now := time.Now()
observed := now.Add(time.Second)
evnt := "my_event"
severity := log.SeverityDebug
severityText := "DBG"
body := log.StringValue("Message")
@@ -25,6 +26,7 @@ func TestRecordFactory(t *testing.T) {
}
got := RecordFactory{
EventName: evnt,
Timestamp: now,
ObservedTimestamp: observed,
Severity: severity,
@@ -33,6 +35,7 @@ func TestRecordFactory(t *testing.T) {
Attributes: attrs,
}.NewRecord()
assert.Equal(t, evnt, got.EventName())
assert.Equal(t, now, got.Timestamp())
assert.Equal(t, observed, got.ObservedTimestamp())
assert.Equal(t, severity, got.Severity())