Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d1cfd08a5 |
Binary file not shown.
+5
-1
@@ -139,7 +139,11 @@ func connectWebSocket(cm *ConfigManager, exec Executor) {
|
|||||||
|
|
||||||
func handleCommand(cm *ConfigManager, msg WSMessage, c MessageWriter, exec Executor) {
|
func handleCommand(cm *ConfigManager, msg WSMessage, c MessageWriter, exec Executor) {
|
||||||
cfg := cm.Get()
|
cfg := cm.Get()
|
||||||
log.Printf("Received command: %s", msg.Type)
|
// Don't log the server's fire-and-forget heartbeat ack — it arrives every
|
||||||
|
// 60s and is not a command to act on; logging it is pure per-minute noise.
|
||||||
|
if msg.Type != "heartbeat_ack" {
|
||||||
|
log.Printf("Received command: %s", msg.Type)
|
||||||
|
}
|
||||||
|
|
||||||
sendResponse := func(status string, message string) {
|
sendResponse := func(status string, message string) {
|
||||||
resp, _ := json.Marshal(map[string]string{"status": status, "message": message})
|
resp, _ := json.Marshal(map[string]string{"status": status, "message": message})
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ func TestHandleCommand(t *testing.T) {
|
|||||||
expectedCmd []string
|
expectedCmd []string
|
||||||
expectedFile string
|
expectedFile string
|
||||||
expectedFileCont string
|
expectedFileCont string
|
||||||
|
// heartbeat_ack (and any fire-and-forget ack) must be silently ignored —
|
||||||
|
// no response message, no command, no log noise.
|
||||||
|
expectedNoResponse bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "config command success",
|
name: "config command success",
|
||||||
@@ -175,6 +178,16 @@ func TestHandleCommand(t *testing.T) {
|
|||||||
expectedStatus: "error",
|
expectedStatus: "error",
|
||||||
expectedCmd: nil,
|
expectedCmd: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "heartbeat_ack is silently ignored",
|
||||||
|
cfg: &Config{
|
||||||
|
Capabilities: Capabilities{},
|
||||||
|
},
|
||||||
|
msg: WSMessage{
|
||||||
|
Type: "heartbeat_ack",
|
||||||
|
},
|
||||||
|
expectedNoResponse: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "unknown command",
|
name: "unknown command",
|
||||||
cfg: &Config{
|
cfg: &Config{
|
||||||
@@ -194,6 +207,16 @@ func TestHandleCommand(t *testing.T) {
|
|||||||
cm := &ConfigManager{current: tc.cfg}
|
cm := &ConfigManager{current: tc.cfg}
|
||||||
handleCommand(cm, tc.msg, mockConn, mockExec)
|
handleCommand(cm, tc.msg, mockConn, mockExec)
|
||||||
|
|
||||||
|
if tc.expectedNoResponse {
|
||||||
|
if len(mockConn.Messages) != 0 {
|
||||||
|
t.Fatalf("expected no response message, got %d: %v", len(mockConn.Messages), mockConn.Messages)
|
||||||
|
}
|
||||||
|
if len(mockExec.ExecutedCommands) > 0 {
|
||||||
|
t.Errorf("expected no commands to be executed, but got %v", mockExec.ExecutedCommands)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(mockConn.Messages) != 1 {
|
if len(mockConn.Messages) != 1 {
|
||||||
t.Fatalf("expected 1 response message, got %d", len(mockConn.Messages))
|
t.Fatalf("expected 1 response message, got %d", len(mockConn.Messages))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user