NOISSUE - Use constants for log level (#240)

* use constants for log level

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* fix tests

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

---------

Signed-off-by: Sammy Oina <sammyoina@gmail.com>
This commit is contained in:
Sammy Kerata Oina
2024-09-13 15:10:19 +03:00
committed by GitHub
parent e26deb98e4
commit 355f95771d
2 changed files with 6 additions and 4 deletions
+3 -2
View File
@@ -6,6 +6,7 @@ import (
"bytes"
"errors"
"io"
"log/slog"
"github.com/ultravioletrs/cocos/pkg/manager"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -62,7 +63,7 @@ func (s *Stdout) Write(p []byte) (n int, err error) {
AgentLog: &manager.AgentLog{
Message: string(buf[:n]),
ComputationId: s.ComputationId,
Level: "debug",
Level: slog.LevelDebug.String(),
Timestamp: timestamppb.Now(),
},
},
@@ -101,7 +102,7 @@ func (s *Stderr) Write(p []byte) (n int, err error) {
AgentLog: &manager.AgentLog{
Message: string(buf[:n]),
ComputationId: s.ComputationId,
Level: "error",
Level: slog.LevelError.String(),
Timestamp: timestamppb.Now(),
},
},
+3 -2
View File
@@ -3,6 +3,7 @@
package vm
import (
"log/slog"
"testing"
"time"
@@ -54,7 +55,7 @@ func TestStdoutWrite(t *testing.T) {
agentLog := msg.GetAgentLog()
assert.NotNil(t, agentLog)
assert.Equal(t, "test-computation", agentLog.ComputationId)
assert.Equal(t, "debug", agentLog.Level)
assert.Equal(t, slog.LevelDebug.String(), agentLog.Level)
assert.NotEmpty(t, agentLog.Message)
assert.NotNil(t, agentLog.Timestamp)
case <-time.After(time.Second):
@@ -113,7 +114,7 @@ func TestStderrWrite(t *testing.T) {
agentLog := msg.GetAgentLog()
assert.NotNil(t, agentLog)
assert.Equal(t, "test-computation", agentLog.ComputationId)
assert.Equal(t, "error", agentLog.Level)
assert.Equal(t, slog.LevelError.String(), agentLog.Level)
assert.NotEmpty(t, agentLog.Message)
assert.NotNil(t, agentLog.Timestamp)
case *manager.ClientStreamMessage_AgentEvent: