-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The problem caused by the mistake in the newLogger function. The nil value is returned even with the valid log format. Signed-off-by: m.nabokikh <[email protected]>
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"log/slog" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewLogger(t *testing.T) { | ||
t.Run("JSON", func(t *testing.T) { | ||
logger, err := newLogger(slog.LevelInfo, "json") | ||
require.NoError(t, err) | ||
require.NotEqual(t, (*slog.Logger)(nil), logger) | ||
}) | ||
|
||
t.Run("Text", func(t *testing.T) { | ||
logger, err := newLogger(slog.LevelError, "text") | ||
require.NoError(t, err) | ||
require.NotEqual(t, (*slog.Logger)(nil), logger) | ||
}) | ||
|
||
t.Run("Unknown", func(t *testing.T) { | ||
logger, err := newLogger(slog.LevelError, "gofmt") | ||
require.Error(t, err) | ||
require.Equal(t, "log format is not one of the supported values (json, text): gofmt", err.Error()) | ||
require.Equal(t, (*slog.Logger)(nil), logger) | ||
}) | ||
} |