Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment on lines +68 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if aws_logs has an invalid json here? Would the test package fail if that happens ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The system test fails on the package if there is an invalid json because the output is not available in the system test config


if err = json.Unmarshal(content, &terraformOutputs); err != nil {
return fmt.Errorf("error during json Unmarshal %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAddTerraformOutputs(t *testing.T) {
Expand All @@ -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",
Expand Down Expand Up @@ -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)
})
}
Expand Down