diff --git a/e2e/health_test.go b/e2e/health_test.go index acca6bef..98689439 100644 --- a/e2e/health_test.go +++ b/e2e/health_test.go @@ -1,6 +1,7 @@ package e2e import ( + "encoding/json" "os/exec" "testing" @@ -9,6 +10,21 @@ import ( "github.com/stretchr/testify/require" ) +const targetDestinationPlaceholder = "TARGET_DESTINATION" + +func replaceNonDeterministicDestination(t *testing.T, out string) string { + t.Helper() + var obj map[string]map[string]interface{} + err := json.Unmarshal([]byte(out), &obj) + require.NoError(t, err) + + obj["target"]["destination"] = targetDestinationPlaceholder + + normalizedOut, err := json.MarshalIndent(obj, "", " ") + require.NoError(t, err) + return string(normalizedOut) +} + func TestHealthCheck(t *testing.T) { container := testutil.StartContainer(t, testutil.DinDContainer) topo := buildBinary(t) @@ -42,6 +58,8 @@ func TestHealthCheck(t *testing.T) { out, err := runCheckHealth(topo, container, "--output", "json") assert.NoError(t, err) + assert.Contains(t, out, container.SSHDestination) + out = replaceNonDeterministicDestination(t, out) testutil.AssertJsonGoldenFile(t, out, "testdata/TestHealthCheckJson.golden") }) } diff --git a/e2e/testdata/TestHealthCheckJson.golden b/e2e/testdata/TestHealthCheckJson.golden index 9ebb9180..1ff44389 100644 --- a/e2e/testdata/TestHealthCheckJson.golden +++ b/e2e/testdata/TestHealthCheckJson.golden @@ -24,7 +24,6 @@ ] }, "target": { - "isLocalhost": false, "connectivity": { "name": "Connectivity", "status": "ok", @@ -42,6 +41,8 @@ "value": "lscpu" } ], + "destination": "TARGET_DESTINATION", + "isLocalhost": false, "subsystemDriver": { "name": "Subsystem Driver (remoteproc)", "status": "info", diff --git a/internal/health/health.go b/internal/health/health.go index 6684fbe9..fd3546e8 100644 --- a/internal/health/health.go +++ b/internal/health/health.go @@ -48,6 +48,7 @@ func (r HostReport) MarshalJSON() ([]byte, error) { } type TargetReport struct { + Destination string `json:"destination"` IsLocalhost bool `json:"isLocalhost"` Connectivity HealthCheck `json:"connectivity"` Dependencies []HealthCheck `json:"dependencies"` @@ -143,6 +144,7 @@ func GenerateTargetReport(targetStatus Status) TargetReport { } report.Dependencies = generateDependencyReport(targetStatus.Dependencies) + report.Destination = targetStatus.Connection.Destination.String() return report } diff --git a/internal/output/templates/health.go b/internal/output/templates/health.go index b4b356dc..73089a1c 100644 --- a/internal/output/templates/health.go +++ b/internal/output/templates/health.go @@ -31,6 +31,7 @@ Host Target ------ {{- if .Target }} +Destination: {{ .Target.Destination }} {{- if not .Target.IsLocalhost }} {{ template "checkRow" .Target.Connectivity }} {{- end }} diff --git a/internal/output/templates/health_test.go b/internal/output/templates/health_test.go index 72c6549d..148203b0 100644 --- a/internal/output/templates/health_test.go +++ b/internal/output/templates/health_test.go @@ -121,6 +121,18 @@ func TestPrintHealthReport(t *testing.T) { assert.Contains(t, out.String(), "❌") }) + t.Run("it renders the target destination", func(t *testing.T) { + toPrint := templates.PrintableHealthReport{ + Target: &health.TargetReport{Destination: "ssh://user@my-target"}, + } + var out bytes.Buffer + + err := printable.Print(toPrint, &out, term.Plain) + + require.NoError(t, err) + assert.Contains(t, out.String(), "Destination: ssh://user@my-target") + }) + t.Run("when not connected, it does not render cpu features", func(t *testing.T) { toPrint := templates.PrintableHealthReport{ Target: &health.TargetReport{ @@ -179,6 +191,7 @@ func TestPrintHealthReport(t *testing.T) { }, }, Target: &health.TargetReport{ + Destination: "ssh://user@my-target", Connectivity: health.HealthCheck{ Name: "Connected", Status: health.CheckStatusOK, @@ -200,6 +213,7 @@ func TestPrintHealthReport(t *testing.T) { ] }, "target": { + "destination": "ssh://user@my-target", "isLocalhost": false, "connectivity": {"name":"Connected","status":"ok","value":""}, "dependencies": [],