From 84e4429ad3bd28e4fb367db0195fc647753c24be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Tue, 9 Jul 2024 16:45:57 +0200 Subject: [PATCH] test: more tests --- cmd/k6exec/error_internal_test.go | 26 ++++++++++++++++++++++++++ cmd/k6exec/main_internal_test.go | 10 ++++++++++ 2 files changed, 36 insertions(+) create mode 100644 cmd/k6exec/error_internal_test.go diff --git a/cmd/k6exec/error_internal_test.go b/cmd/k6exec/error_internal_test.go new file mode 100644 index 0000000..5eb63f0 --- /dev/null +++ b/cmd/k6exec/error_internal_test.go @@ -0,0 +1,26 @@ +package main + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/require" +) + +type testError struct { +} + +func (*testError) Error() string { + return "test error" +} + +func (*testError) Format(_ int, _ bool) string { + return "formatted test error" +} + +func Test_formatError(t *testing.T) { + t.Parallel() + + require.Equal(t, errors.ErrUnsupported.Error(), formatError(errors.ErrUnsupported)) + require.Equal(t, "formatted test error", formatError(new(testError))) +} diff --git a/cmd/k6exec/main_internal_test.go b/cmd/k6exec/main_internal_test.go index 513d639..92de281 100644 --- a/cmd/k6exec/main_internal_test.go +++ b/cmd/k6exec/main_internal_test.go @@ -6,6 +6,8 @@ import ( "runtime" "testing" + sloglogrus "github.com/samber/slog-logrus/v2" + "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" ) @@ -24,3 +26,11 @@ func Test_newCmd(t *testing.T) { //nolint:paralleltest require.NoError(t, cmd.Execute()) } + +func Test_initLogging(t *testing.T) { + lvar := initLogging(appname) + + require.NotNil(t, lvar) + require.Equal(t, logrus.DebugLevel, logrus.GetLevel()) + require.IsType(t, new(sloglogrus.LogrusHandler), slog.Default().Handler()) +}