File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
internal/testrunner/runners/system/servicedeployer Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ func addTerraformOutputs(outCtxt ServiceContext) error {
6464 // Unmarshall the data into `terraformOutputs`
6565 logger .Debug ("Unmarshalling terraform output json" )
6666 var terraformOutputs map [string ]OutputMeta
67+
68+ if ! json .Valid (content ) {
69+ logger .Debug ("Invalid Json content in the terraform output file, skipped creating outputs" )
70+ return nil
71+ }
72+
6773 if err = json .Unmarshal (content , & terraformOutputs ); err != nil {
6874 return fmt .Errorf ("error during json Unmarshal %w" , err )
6975 }
Original file line number Diff line number Diff line change 99 "testing"
1010
1111 "github.com/stretchr/testify/assert"
12+ "github.com/stretchr/testify/require"
1213)
1314
1415func TestAddTerraformOutputs (t * testing.T ) {
@@ -20,6 +21,28 @@ func TestAddTerraformOutputs(t *testing.T) {
2021 content []byte
2122 expectedProps map [string ]interface {}
2223 }{
24+ {
25+ testName : "invalid_json_output" ,
26+ runId : "987987" ,
27+ ctxt : ServiceContext {
28+ Test : struct { RunID string }{"987987" },
29+ },
30+ content : []byte (
31+ `` ,
32+ ),
33+ expectedProps : map [string ]interface {}{},
34+ },
35+ {
36+ testName : "empty_json_output" ,
37+ runId : "v" ,
38+ ctxt : ServiceContext {
39+ Test : struct { RunID string }{"9887" },
40+ },
41+ content : []byte (
42+ `{}` ,
43+ ),
44+ expectedProps : map [string ]interface {}{},
45+ },
2346 {
2447 testName : "single_value_output" ,
2548 runId : "99999" ,
@@ -121,7 +144,8 @@ func TestAddTerraformOutputs(t *testing.T) {
121144 }
122145
123146 // Test that the terraform output values are generated correctly
124- addTerraformOutputs (tc .ctxt )
147+ err := addTerraformOutputs (tc .ctxt )
148+ require .NoError (t , err )
125149 assert .Equal (t , tc .expectedProps , tc .ctxt .CustomProperties )
126150 })
127151 }
You can’t perform that action at this time.
0 commit comments