diff --git a/internal/testrunner/runners/system/servicedeployer/terraform.go b/internal/testrunner/runners/system/servicedeployer/terraform.go index 6a191d244e..67b79e6fca 100644 --- a/internal/testrunner/runners/system/servicedeployer/terraform.go +++ b/internal/testrunner/runners/system/servicedeployer/terraform.go @@ -64,6 +64,12 @@ func addTerraformOutputs(outCtxt ServiceContext) error { // Unmarshall the data into `terraformOutputs` logger.Debug("Unmarshalling terraform output json") var terraformOutputs map[string]OutputMeta + + if !json.Valid(content) { + logger.Debug("Invalid Json content in the terraform output file, skipped creating outputs") + return nil + } + if err = json.Unmarshal(content, &terraformOutputs); err != nil { return fmt.Errorf("error during json Unmarshal %w", err) } diff --git a/internal/testrunner/runners/system/servicedeployer/terraform_test.go b/internal/testrunner/runners/system/servicedeployer/terraform_test.go index 30d822f455..ce19808beb 100644 --- a/internal/testrunner/runners/system/servicedeployer/terraform_test.go +++ b/internal/testrunner/runners/system/servicedeployer/terraform_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestAddTerraformOutputs(t *testing.T) { @@ -20,6 +21,28 @@ func TestAddTerraformOutputs(t *testing.T) { content []byte expectedProps map[string]interface{} }{ + { + testName: "invalid_json_output", + runId: "987987", + ctxt: ServiceContext{ + Test: struct{ RunID string }{"987987"}, + }, + content: []byte( + ``, + ), + expectedProps: map[string]interface{}{}, + }, + { + testName: "empty_json_output", + runId: "v", + ctxt: ServiceContext{ + Test: struct{ RunID string }{"9887"}, + }, + content: []byte( + `{}`, + ), + expectedProps: map[string]interface{}{}, + }, { testName: "single_value_output", runId: "99999", @@ -121,7 +144,8 @@ func TestAddTerraformOutputs(t *testing.T) { } // Test that the terraform output values are generated correctly - addTerraformOutputs(tc.ctxt) + err := addTerraformOutputs(tc.ctxt) + require.NoError(t, err) assert.Equal(t, tc.expectedProps, tc.ctxt.CustomProperties) }) }