Skip to content

Commit

Permalink
add level tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arianvp committed Jan 12, 2025
1 parent 0cf63db commit 7d3e250
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,45 @@ func TestCanWriteMessageToSocket(t *testing.T) {
})

}

func TestLevel(t *testing.T) {
l := LevelVar{}
if l.Level() != slog.LevelInfo {
t.Error("expected LevelInfo")
}

h, err := NewHandler(nil)
if err != nil {
t.Fatal(err)
}
if h.opts.Level.Level() != slog.LevelInfo {
t.Error("expected LevelInfo")
}

l = LevelVar{}
os.Setenv("DEBUG_INVOCATION", "1")
if l.Level() != slog.LevelDebug {
t.Error("expected LevelDebug")
}

h, err = NewHandler(nil)
if err != nil {
t.Fatal(err)
}
if h.opts.Level.Level() != slog.LevelDebug {
t.Error("expected LevelDebug")
}

h, err = NewHandler(&Options{Level: slog.LevelError})
if err != nil {
t.Fatal(err)
}
if h.opts.Level.Level() != slog.LevelError {
t.Error("expected LevelError")
}

if !h.Enabled(context.TODO(), slog.LevelError) {
t.Error("expected true")
}

}

0 comments on commit 7d3e250

Please sign in to comment.