Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the out of boundary error #9628

Merged
merged 1 commit into from
Dec 13, 2023
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 @@ -31,7 +31,7 @@ func removeComputedKeys(old map[string]interface{}, new map[string]interface{})

if reflect.ValueOf(v).Kind() == reflect.Slice {
for i, j := range v.([]interface{}) {
if reflect.ValueOf(j).Kind() == reflect.Map {
if reflect.ValueOf(j).Kind() == reflect.Map && len(new[k].([]interface{})) > i {
old[k].([]interface{})[i] = removeComputedKeys(j.(map[string]interface{}), new[k].([]interface{})[i].(map[string]interface{}))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ func TestAccMonitoringDashboard_update(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"project"},
},
{
Config: testAccMonitoringDashboard_gridLayoutUpdate(),
},
{
ResourceName: "google_monitoring_dashboard.dashboard",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"project"},
Copy link
Member

Choose a reason for hiding this comment

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

What do each of these fields e.g. ImportState do? I read what appears to be the relevant document at https://googlecloudplatform.github.io/magic-modules/develop/test/ - perhaps I am missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

These fields are used to test if importing the resource works or not.

ImportState triggers the import testing mode. ImportStateVerify will compare the state after import with the server side response. ImportStateVerifyIgnore will not compare the ignored fields.

},
},
})
}
Expand Down Expand Up @@ -242,6 +251,52 @@ EOF
`)
}

func testAccMonitoringDashboard_gridLayoutUpdate() string {
Copy link
Member

Choose a reason for hiding this comment

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

Does the addition of this test mean that updating the grid layout is sufficient to trigger the index out of range crash?

If so, thank you for adding this to prevent a future regression!

Copy link
Member

Choose a reason for hiding this comment

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

Actually, it appears there is already testAccMonitoringDashboard_gridLayout - maybe this deserves a comment as to how this is different? Fwiw, I can't tell from the name how the intention behind testAccMonitoringDashboard_gridLayoutUpdate is supposed to be different from testAccMonitoringDashboard_gridLayout

Copy link
Member Author

Choose a reason for hiding this comment

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

This test triggers the index out of range crash. With the fix in this PR, this test passed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the comment will help.

return fmt.Sprintf(`
resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = <<EOF
{
"displayName": "Grid Layout Example",
"gridLayout": {
"columns": "2",
"widgets": [
{
"title": "Widget 1",
"xyChart": {
"dataSets": [{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"agent.googleapis.com/nginx/connections/accepted_count\"",
"aggregation": {
"perSeriesAligner": "ALIGN_RATE"
}
},
"unitOverride": "1"
},
"plotType": "LINE"
}],
"timeshiftDuration": "0s",
"yAxis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
},
{
"text": {
"content": "Widget 2",
"format": "MARKDOWN"
}
}
]
}
}

EOF
}
`)
}

func testAccMonitoringDashboard_rowLayout() string {
return fmt.Sprintf(`
resource "google_monitoring_dashboard" "dashboard" {
Expand Down