test(go): assert ping echo in JSON output; comment ping fallback
TestRunPingJSON now verifies the fake gateway's echoed text appears in the serialised reply body, catching any future wiring regression that maps PingRaw to the wrong proto field. runPing gains a one-line comment explaining why DiagnosticMessage carries the echo, why the kind-string fallback exists, and why writeCommandOutput is not reused on the plain-text path.
This commit is contained in:
@@ -263,6 +263,11 @@ func runPing(ctx context.Context, args []string, stdout, stderr io.Writer) error
|
||||
Reply: mustMarshalProto(reply),
|
||||
})
|
||||
}
|
||||
// DiagnosticMessage carries the echoed ping text set by the gateway.
|
||||
// Fall back to the kind string when the gateway returns an empty message
|
||||
// (forward-compat guard for future gateway versions). writeCommandOutput
|
||||
// is not reused here because it would print the opaque Kind enum rather
|
||||
// than the human-readable echo.
|
||||
echo := reply.GetDiagnosticMessage()
|
||||
if echo == "" {
|
||||
echo = reply.GetKind().String()
|
||||
|
||||
@@ -255,6 +255,13 @@ func TestRunPingJSON(t *testing.T) {
|
||||
if out.Command != "ping" {
|
||||
t.Fatalf("command = %q, want %q", out.Command, "ping")
|
||||
}
|
||||
// The fake gateway echoes "pong:<message>" in diagnostic_message; verify the
|
||||
// echo appears in the serialised reply so a future regression that wired
|
||||
// PingRaw to the wrong proto field would be caught here.
|
||||
replyStr := string(out.Reply)
|
||||
if !strings.Contains(replyStr, "pong:hello") {
|
||||
t.Fatalf("ping JSON reply missing echoed message %q; reply = %s", "pong:hello", replyStr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunPingRequiresSessionID verifies the ping subcommand rejects missing session-id.
|
||||
|
||||
Reference in New Issue
Block a user