Skip to content

Commit

Permalink
Add test for allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Mar 5, 2024
1 parent 64b4fbc commit fb7680a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,28 @@ func BenchmarkLoggerMemory(b *testing.B) {
}
}
}

func TestLoggerMemory(t *testing.T) {
var buf bytes.Buffer

logger := New(&LoggerOptions{
Name: "test",
Output: &buf,
Level: Info,
})

avg := testing.AllocsPerRun(100, func() {
logger.Trace("this is some message",
"name", "foo",
"what", "benchmarking yourself",
)

if buf.Len() != 0 {
panic("oops")
}
})

if avg != 0 {
t.Fatalf("ignored logs allocated")
}
}

0 comments on commit fb7680a

Please sign in to comment.