@@ -18,6 +18,7 @@ func TestEvalCommand(t *testing.T) {
1818 policy string
1919 failsWith error
2020 skip bool
21+ verbose bool
2122 }{
2223 {
2324 name : "invalid policy path given" ,
@@ -130,6 +131,22 @@ func TestEvalCommand(t *testing.T) {
130131 policy : "testdata/policy/individuals/no_passing_valid.rego" ,
131132 failsWith : commands .PolicyFailure ,
132133 },
134+ {
135+ name : "verbosity on success should print trace information" ,
136+ template : "testdata/templates" ,
137+ values : []string {"testdata/values.yml" , "testdata/added_values.yml" },
138+ policy : "testdata/policy/individuals/multiple_values.rego" ,
139+ failsWith : nil ,
140+ verbose : true ,
141+ },
142+ {
143+ name : "verbosity on failure should print trace information" ,
144+ template : "testdata/templates" ,
145+ values : []string {"testdata/values.yml" },
146+ policy : "testdata/policy/individuals/no_passing_valid.rego" ,
147+ failsWith : commands .PolicyFailure ,
148+ verbose : true ,
149+ },
133150 } {
134151 t .Run (tt .name , func (t * testing.T ) {
135152 if tt .skip {
@@ -142,12 +159,21 @@ func TestEvalCommand(t *testing.T) {
142159 Template : tt .template ,
143160 Policy : tt .policy ,
144161 Values : tt .values ,
162+ Verbose : tt .verbose ,
145163 }
146164 err := evalCmd .Execute ([]string {})
147165 if err != nil && ! errors .Is (err , tt .failsWith ) {
148166 t .Errorf ("expected error:\n %v\n got:\n %v" , tt .failsWith , err )
149167 }
150168
169+ if ! tt .verbose && stdOut .Len () > 0 {
170+ t .Errorf ("when verbose is off this should always be empty, but it contains %v bytes" , stdOut .Len ())
171+ }
172+
173+ if tt .verbose && stdOut .Len () == 0 {
174+ t .Errorf ("we expected to print verbose trace information, but it is empty" )
175+ }
176+
151177 if err == nil && tt .failsWith != nil {
152178 t .Errorf ("expected a failing policy %w but no failures found" , tt .failsWith )
153179 }
0 commit comments