@@ -20,6 +20,8 @@ import (
2020 "testing"
2121
2222 "github.com/rs/zerolog"
23+ "github.com/stretchr/testify/assert"
24+ "github.com/stretchr/testify/require"
2325)
2426
2527func TestZerologMetricsMetadata (t * testing.T ) {
@@ -35,22 +37,13 @@ func TestZerologMetricsMetadata(t *testing.T) {
3537
3638 line := buf .String ()
3739 var m map [string ]any
38- if err := json .Unmarshal ([]byte (line ), & m ); err != nil {
39- t .Fatalf ("failed to parse log: %v" , err )
40- }
40+ err := json .Unmarshal ([]byte (line ), & m )
41+ require .NoError (t , err , "failed to parse log output" )
4142
42- if got := m ["containerID" ]; got != "container00" {
43- t .Errorf ("containerID = %v, want container00" , got )
44- }
45- if got := m ["timestampID" ]; got != "TS00" {
46- t .Errorf ("timestampID = %v, want TS00" , got )
47- }
48- if got := m ["timestampName" ]; got != "CR.invoked" {
49- t .Errorf ("timestampName = %v, want CR.invoked" , got )
50- }
51- if got := int (m ["timestampOrder" ].(float64 )); got != 0 {
52- t .Errorf ("timestampOrder = %v, want 0" , got )
53- }
43+ assert .Equal (t , "container00" , m ["containerID" ], "containerID mismatch" )
44+ assert .Equal (t , "TS00" , m ["timestampID" ], "timestampID mismatch" )
45+ assert .Equal (t , "CR.invoked" , m ["timestampName" ], "timestampName mismatch" )
46+ assert .Equal (t , float64 (0 ), m ["timestampOrder" ], "timestampOrder mismatch" )
5447}
5548
5649func TestZerologMetricsInvalidFileDoesNotPanic (t * testing.T ) {
@@ -60,7 +53,5 @@ func TestZerologMetricsInvalidFileDoesNotPanic(t *testing.T) {
6053 // Create the metrics writer with timestamps enabled but an invalid path
6154 writer := NewZerologMetrics (true , invalidPath , "container-test" )
6255
63- if writer == nil {
64- t .Fatal ("expected non-nil writer (fallback to mockWriter), got nil" )
65- }
56+ require .NotNil (t , writer , "expected non-nil writer (fallback to mockWriter), got nil" )
6657}
0 commit comments