Skip to content

Commit 4dcff8b

Browse files
committed
fix: debug log typo
1 parent b56df57 commit 4dcff8b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

internal/interpreter/base_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (e *baseExecutor) Execute(ctx context.Context, message *Message, device age
6464
logger.Error("Whoami check failed", "error", err, "combined_output", combinedOutput)
6565
}
6666

67-
logger.Debug("Whomai", "user", combinedOutput)
67+
logger.Debug("Whoami", "user", combinedOutput)
6868
}
6969

7070
// Save commands to temporary file

internal/interpreter/message_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/base64"
77
"encoding/json"
88
"net/http"
9+
"strings"
910
"testing"
1011

1112
"github.com/RewstApp/agent-smith-go/internal/agent"
@@ -213,6 +214,38 @@ func TestMessage_Execute_GetInstallation(t *testing.T) {
213214
}
214215
}
215216

217+
func TestMessage_Execute_DebugLogger_WritesEntries(t *testing.T) {
218+
var buf bytes.Buffer
219+
logger := hclog.New(&hclog.LoggerOptions{
220+
Output: &buf,
221+
Level: hclog.Debug,
222+
})
223+
msg := Message{
224+
PostId: "test:123",
225+
Commands: encodeCommand("echo 'hello world'"),
226+
}
227+
device := agent.Device{RewstOrgId: "test-org"}
228+
executor := NewExecutor()
229+
sys := &mockSystemInfoProvider{}
230+
domain := &mockDomainInfoProvider{}
231+
232+
msg.Execute(executor, context.Background(), device, logger, sys, domain)
233+
234+
if buf.Len() == 0 {
235+
t.Error("expected log entries to be written, but buffer is empty")
236+
}
237+
238+
logs := buf.String()
239+
240+
if !strings.Contains(strings.ToLower(logs), "[debug] shell version") {
241+
t.Errorf("expected log entries to write shell version, but not found in %s", logs)
242+
}
243+
244+
if !strings.Contains(strings.ToLower(logs), "[debug] whoami") {
245+
t.Errorf("expected log entries to write whoami, but not found in %s", logs)
246+
}
247+
}
248+
216249
func TestMessage_CreatePostbackRequest_MultipleColons(t *testing.T) {
217250
msg := Message{
218251
PostId: "a:b:c",

0 commit comments

Comments
 (0)