@@ -3,12 +3,15 @@ package output_test
33import (
44 "bytes"
55 "errors"
6+ "io"
7+ "strings"
68 "testing"
79
810 "github.com/UpCloudLtd/upcloud-cli/v3/internal/config"
911 "github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
1012
1113 "github.com/stretchr/testify/assert"
14+ "github.com/stretchr/testify/require"
1215)
1316
1417type failWriter struct {}
@@ -26,22 +29,30 @@ func TestRenderFailingWriter(t *testing.T) {
2629}
2730
2831func TestRender (t * testing.T ) {
32+ rr := strings .NewReader ("raw hello" )
2933 renderTests := []outputTestCase {
3034 {
3135 name : "none" ,
3236 input : output.None {},
33- expectedHumanResult : "\n " ,
34- expectedJSONResult : "\n " ,
37+ expectedHumanResult : "" ,
38+ expectedJSONResult : "" ,
3539 expectedYAMLResult : "" ,
3640 },
3741 {
3842 name : "marshaled" ,
3943 input : output.OnlyMarshaled {Value : "hello" },
40- expectedHumanResult : "\n " , // marshaled should not output in human mode
44+ expectedHumanResult : "" , // marshaled should not output in human mode
4145 expectedJSONResult : `"hello"
4246` ,
4347 expectedYAMLResult : "hello\n " ,
4448 },
49+ {
50+ name : "raw" ,
51+ input : output.Raw {Source : io .NopCloser (rr )},
52+ expectedHumanResult : "raw hello" ,
53+ expectedJSONResult : "raw hello" ,
54+ expectedYAMLResult : "raw hello" ,
55+ },
4556 }
4657 for _ , test := range renderTests {
4758 t .Run (test .name , func (t * testing.T ) {
@@ -51,11 +62,15 @@ func TestRender(t *testing.T) {
5162 cfg .Viper ().Set (config .KeyOutput , "human" )
5263 err := output .Render (out , cfg .Output (), test .input )
5364 validateOutput (t , test .expectedHumanResult , test .expectedErrorMessage , out .Bytes (), err )
65+ _ , err = rr .Seek (0 , io .SeekStart )
66+ require .NoError (t , err )
5467 out .Truncate (0 )
5568
5669 cfg .Viper ().Set (config .KeyOutput , "json" )
5770 err = output .Render (out , cfg .Output (), test .input )
5871 validateOutput (t , test .expectedJSONResult , test .expectedErrorMessage , out .Bytes (), err )
72+ _ , err = rr .Seek (0 , io .SeekStart )
73+ require .NoError (t , err )
5974 out .Truncate (0 )
6075
6176 cfg .Viper ().Set (config .KeyOutput , "yaml" )
0 commit comments