Skip to content

Commit

Permalink
logtest: Add EventName to RecordFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Jan 21, 2025
1 parent e01aace commit 7ea51a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions log/logtest/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestAssertRecord(t *testing.T) {
AssertRecordEqual(t, r1, r2)

now := time.Now()
r1.SetEventName("my event")
r2.SetEventName("my event")
r1.SetEventName("my_event")
r2.SetEventName("my_event")
r1.SetTimestamp(now)
r2.SetTimestamp(now)
r1.SetObservedTimestamp(now)
Expand Down
2 changes: 2 additions & 0 deletions log/logtest/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions log/logtest/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -25,6 +26,7 @@ func TestRecordFactory(t *testing.T) {
}

got := RecordFactory{
EventName: evnt,
Timestamp: now,
ObservedTimestamp: observed,
Severity: severity,
Expand All @@ -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())
Expand Down

0 comments on commit 7ea51a2

Please sign in to comment.