Repository: FairwindsOps/pluto
Pull request #101 (2020-07-09 20:13:19)

Fix JSON/YAML output when there are no outputs
We're running
```
$ pluto detect-helm -ojson > /output/pluto.json;
```

When there are no deprecated resources in the cluster, this results in
```
$ cat /output/pluto.json
There were no apiVersions found that match our records.
```

which is not valid JSON

rbren: Bader and I were a bit confused by the message too, so I updated here - happy to revert or change.
codecov[bot]: # [Codecov](https://codecov.io/gh/FairwindsOps/pluto/pull/101?src=pr&el=h1) Report
> Merging [#101](https://codecov.io/gh/FairwindsOps/pluto/pull/101?src=pr&el=desc) into [master](https://codecov.io/gh/FairwindsOps/pluto/commit/20f146def8303190c923c5ec592a135b46da1c1a&el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/FairwindsOps/pluto/pull/101/graphs/tree.svg?width=650&height=150&src=pr&token=A23F79JTNA)](https://codecov.io/gh/FairwindsOps/pluto/pull/101?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #101   +/-   ##
=======================================
  Coverage   80.18%   80.18%           
=======================================
  Files           5        5           
  Lines         439      439           
=======================================
  Hits          352      352           
  Misses         58       58           
  Partials       29       29           
```


| [Impacted Files](https://codecov.io/gh/FairwindsOps/pluto/pull/101?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/api/output.go](https://codecov.io/gh/FairwindsOps/pluto/pull/101/diff?src=pr&el=tree#diff-cGtnL2FwaS9vdXRwdXQuZ28=) | `87.36% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/FairwindsOps/pluto/pull/101?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/FairwindsOps/pluto/pull/101?src=pr&el=footer). Last update [20f146d...0abb725](https://codecov.io/gh/FairwindsOps/pluto/pull/101?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pkg/api/output.go b/pkg/api/output.go
index 2e99648..85d543f 100644
--- a/pkg/api/output.go
+++ b/pkg/api/output.go
@@ -33,8 +33,8 @@ type Instance struct {
 
 // DisplayOutput prints the output based on desired variables
 func (instance *Instance) DisplayOutput() error {
-	if len(instance.Outputs) == 0 {
-		fmt.Println("There were no apiVersions found that match our records.")
+	if len(instance.Outputs) == 0 && (instance.OutputFormat == "normal" || instance.OutputFormat == "wide") {
+		fmt.Println("There were no resources found with known deprecated apiVersions.")
 		return nil
 	}
 	instance.filterOutput()


Test patch:
diff --git a/pkg/api/output_test.go b/pkg/api/output_test.go
index 5b6f552..cb02faa 100644
--- a/pkg/api/output_test.go
+++ b/pkg/api/output_test.go
@@ -230,7 +230,7 @@ func ExampleInstance_DisplayOutput_zeroLength() {
 	}
 	_ = instance.DisplayOutput()
 
-	// Output: There were no apiVersions found that match our records.
+	// Output: There were no resources found with known deprecated apiVersions.
 }
 
 func TestGetReturnCode(t *testing.T) {