Passed
Pull Request — main (#166)
by Yume
02:12
created

cmd/v2/config/viper_test.go   A

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 33
dl 0
loc 50
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A config_test.TestLogConfig_GetSlogLevel 0 40 3
1
package config_test
2
3
import (
4
	"log/slog"
5
	"testing"
6
7
	"github.com/memnix/memnix-rest/cmd/v2/config"
8
	"github.com/stretchr/testify/assert"
9
)
10
11
func TestLogConfig_GetSlogLevel(t *testing.T) {
12
	tests := []struct {
13
		name     string
14
		level    string
15
		expected slog.Level
16
	}{
17
		{
18
			name:     "DebugLevel",
19
			level:    "debug",
20
			expected: slog.LevelDebug,
21
		},
22
		{
23
			name:     "InfoLevel",
24
			level:    "info",
25
			expected: slog.LevelInfo,
26
		},
27
		{
28
			name:     "WarnLevel",
29
			level:    "warn",
30
			expected: slog.LevelWarn,
31
		},
32
		{
33
			name:     "ErrorLevel",
34
			level:    "error",
35
			expected: slog.LevelError,
36
		},
37
		{
38
			name:     "DefaultLevel",
39
			level:    "unknown",
40
			expected: slog.LevelInfo,
41
		},
42
	}
43
44
	for _, tt := range tests {
45
		t.Run(tt.name, func(t *testing.T) {
46
			logConfig := config.LogConfig{
47
				Level: tt.level,
48
			}
49
			actual := logConfig.GetSlogLevel()
50
			assert.Equal(t, tt.expected, actual)
51
		})
52
	}
53
}
54