Skip to content

Commit 0be90bf

Browse files
rocketeerbkwshreddedbacon
authored andcommitted
fix: info messages not printed with --output-json
1 parent 3c4e1bd commit 0be90bf

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

pkg/output/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func RenderInfo(infoMsg string, opts Options) {
7575
jsonData := Result{
7676
Info: trimQuotes(infoMsg),
7777
}
78-
RenderJSON(jsonData, opts)
78+
fmt.Fprintf(os.Stderr, "%s", RenderJSON(jsonData, opts))
7979
} else {
8080
fmt.Fprintf(os.Stderr, "Info: %s", trimQuotes(infoMsg))
8181
}

pkg/output/main_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,17 @@ func TestRenderInfo(t *testing.T) {
7676
Pretty: false,
7777
}
7878

79-
rescueStdout := os.Stderr
80-
r, w, _ := os.Pipe()
81-
defer func() {
82-
os.Stderr = rescueStdout
83-
}()
84-
os.Stderr = w
85-
RenderInfo(testData, outputOptions)
86-
w.Close()
87-
var out bytes.Buffer
88-
_, _ = io.Copy(&out, r)
89-
if out.String() != testSuccess1 {
90-
checkEqual(t, out.String(), testSuccess1, " render info stdout processing failed")
91-
}
79+
out := captureStderr(func() {
80+
RenderInfo(testData, outputOptions)
81+
})
82+
checkEqual(t, out, testSuccess1, " render info stdout processing failed")
83+
84+
var testJson = `{"info":"Info Message"}`
85+
outputOptions.JSON = true
86+
out = captureStderr(func() {
87+
RenderInfo(testData, outputOptions)
88+
})
89+
checkEqual(t, out, testJson, " render error stdout processing failed")
9290
}
9391

9492
func TestRenderOutput(t *testing.T) {

0 commit comments

Comments
 (0)