Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions e2e/health_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"encoding/json"
"os/exec"
"testing"

Expand All @@ -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)
Expand Down Expand Up @@ -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")
})
}
Expand Down
3 changes: 2 additions & 1 deletion e2e/testdata/TestHealthCheckJson.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
]
},
"target": {
"isLocalhost": false,
"connectivity": {
"name": "Connectivity",
"status": "ok",
Expand All @@ -42,6 +41,8 @@
"value": "lscpu"
}
],
"destination": "TARGET_DESTINATION",
"isLocalhost": false,
"subsystemDriver": {
"name": "Subsystem Driver (remoteproc)",
"status": "info",
Expand Down
2 changes: 2 additions & 0 deletions internal/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -143,6 +144,7 @@ func GenerateTargetReport(targetStatus Status) TargetReport {
}

report.Dependencies = generateDependencyReport(targetStatus.Dependencies)
report.Destination = targetStatus.Connection.Destination.String()

return report
}
Expand Down
1 change: 1 addition & 0 deletions internal/output/templates/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Host
Target
------
{{- if .Target }}
Destination: {{ .Target.Destination }}
{{- if not .Target.IsLocalhost }}
{{ template "checkRow" .Target.Connectivity }}
{{- end }}
Expand Down
14 changes: 14 additions & 0 deletions internal/output/templates/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -200,6 +213,7 @@ func TestPrintHealthReport(t *testing.T) {
]
},
"target": {
"destination": "ssh://user@my-target",
"isLocalhost": false,
"connectivity": {"name":"Connected","status":"ok","value":""},
"dependencies": [],
Expand Down
Loading