@@ -87,7 +87,8 @@ func TestGenerateTargetReport(t *testing.T) {
8787 got := health .GenerateTargetReport (ts )
8888
8989 assert .Equal (t , health .CheckStatusError , got .Connectivity .Status )
90- assert .Contains (t , got .Connectivity .Fix , "topo setup-keys --target ssh://user@my-target" )
90+ assert .Equal (t , "Configure SSH keys on remote target" , got .Connectivity .Fix .Description )
91+ assert .Equal (t , "topo setup-keys --target ssh://user@my-target" , got .Connectivity .Fix .Command )
9192 })
9293
9394 t .Run ("when host key is new, Connectivity includes an accept-new-host-keys fix" , func (t * testing.T ) {
@@ -101,7 +102,8 @@ func TestGenerateTargetReport(t *testing.T) {
101102 got := health .GenerateTargetReport (ts )
102103
103104 assert .Equal (t , health .CheckStatusError , got .Connectivity .Status )
104- assert .Equal (t , "run `topo health --target ssh://user@my-target --accept-new-host-keys` to trust the target's identity" , got .Connectivity .Fix )
105+ assert .Equal (t , "Trust the target's SSH host key" , got .Connectivity .Fix .Description )
106+ assert .Equal (t , "topo health --target ssh://user@my-target --accept-new-host-keys" , got .Connectivity .Fix .Command )
105107 })
106108
107109 t .Run ("when host key has changed, Connectivity includes a known_hosts fix" , func (t * testing.T ) {
@@ -115,7 +117,8 @@ func TestGenerateTargetReport(t *testing.T) {
115117 got := health .GenerateTargetReport (ts )
116118
117119 assert .Equal (t , health .CheckStatusError , got .Connectivity .Status )
118- assert .Equal (t , "run `ssh-keygen -R my-target` to remove the old host key, then retry" , got .Connectivity .Fix )
120+ assert .Equal (t , "Remove the old SSH host key from known_hosts, then retry" , got .Connectivity .Fix .Description )
121+ assert .Equal (t , "ssh-keygen -R my-target" , got .Connectivity .Fix .Command )
119122 })
120123}
121124
@@ -130,6 +133,36 @@ func TestHostReport(t *testing.T) {
130133 want := `{ "dependencies": [] }`
131134 assert .JSONEq (t , want , string (b ))
132135 })
136+
137+ t .Run ("omits command when fix has no command" , func (t * testing.T ) {
138+ tr := health.HostReport {Dependencies : []health.HealthCheck {
139+ {
140+ Name : "Container Engine" ,
141+ Status : health .CheckStatusError ,
142+ Value : "permission denied" ,
143+ Fix : & health.Fix {
144+ Description : "Ensure current user can run docker commands" ,
145+ },
146+ },
147+ }}
148+
149+ b , err := json .Marshal (tr )
150+
151+ require .NoError (t , err )
152+ want := `{
153+ "dependencies": [
154+ {
155+ "name": "Container Engine",
156+ "status": "error",
157+ "value": "permission denied",
158+ "fix": {
159+ "description": "Ensure current user can run docker commands"
160+ }
161+ }
162+ ]
163+ }`
164+ assert .JSONEq (t , want , string (b ))
165+ })
133166 })
134167}
135168
@@ -180,14 +213,25 @@ func testDependencyReporting(t *testing.T, extract func([]health.DependencyStatu
180213 {
181214 Dependency : health.Dependency {Binary : "pizza" , Label : "Food" },
182215 Error : health.WarningError {Err : errors .New ("not enough pineapple" )},
183- Fix : "add more pineapple" ,
216+ Fix : & health.Fix {
217+ Description : "add more pineapple" ,
218+ Command : "pizza --pineapple" ,
219+ },
184220 },
185221 }
186222
187223 got := extract (statuses )
188224
189225 want := []health.HealthCheck {
190- {Name : "Food" , Status : health .CheckStatusWarning , Value : "not enough pineapple" , Fix : "add more pineapple" },
226+ {
227+ Name : "Food" ,
228+ Status : health .CheckStatusWarning ,
229+ Value : "not enough pineapple" ,
230+ Fix : & health.Fix {
231+ Description : "add more pineapple" ,
232+ Command : "pizza --pineapple" ,
233+ },
234+ },
191235 }
192236 assert .Equal (t , want , got )
193237 })
0 commit comments