MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / testLevel

Function testLevel

log/logger_test.go:33–75  ·  view source on GitHub ↗
(t *testing.T, logLevel config.LogLevel, writeLogLevel config.LogLevel)

Source from the content-addressed store, hash-verified

31}
32
33func testLevel(t *testing.T, logLevel config.LogLevel, writeLogLevel config.LogLevel) {
34 var buf bytes.Buffer
35 p := log.MustNewLogger(config.LogConfig{
36 Level: logLevel,
37 Format: config.LogFormatLJSON,
38 Destination: config.LogDestinationStdout,
39 Stdout: &buf,
40 })
41 msg := message.UserMessage("E_TEST", "test", "test")
42 switch writeLogLevel {
43 case config.LogLevelDebug:
44 p.Debug(msg)
45 case config.LogLevelInfo:
46 p.Info(msg)
47 case config.LogLevelNotice:
48 p.Notice(msg)
49 case config.LogLevelWarning:
50 p.Warning(msg)
51 case config.LogLevelError:
52 p.Error(msg)
53 case config.LogLevelCritical:
54 p.Critical(msg)
55 case config.LogLevelAlert:
56 p.Alert(msg)
57 case config.LogLevelEmergency:
58 p.Emergency(msg)
59 }
60 if logLevel < writeLogLevel {
61 assert.Equal(t, 0, buf.Len())
62 } else {
63 assert.NotEqual(t, 0, buf.Len())
64
65 rawData := buf.Bytes()
66 data := map[string]interface{}{}
67 if err := json.Unmarshal(rawData, &data); err != nil {
68 assert.Fail(t, "failed to unmarshal JSON from writer", err)
69 }
70
71 expectedLevel := writeLogLevel.String()
72 assert.Equal(t, expectedLevel, data["level"])
73 assert.Equal(t, "test", data["message"])
74 }
75}

Callers 1

TestLogLevelFilteringFunction · 0.85

Calls 13

MustNewLoggerFunction · 0.92
UserMessageFunction · 0.92
UnmarshalMethod · 0.80
FailMethod · 0.80
DebugMethod · 0.65
InfoMethod · 0.65
NoticeMethod · 0.65
WarningMethod · 0.65
ErrorMethod · 0.65
CriticalMethod · 0.65
AlertMethod · 0.65
EmergencyMethod · 0.65

Tested by

no test coverage detected