Skip to content

Commit

Permalink
fix(dashboards): remove omitempty on widgets to allow creating pages …
Browse files Browse the repository at this point in the history
…with no widgets (#1033)
  • Loading branch information
pranav-new-relic committed Jun 19, 2023
1 parent 61ce5b3 commit 7ba7df9
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
84 changes: 84 additions & 0 deletions pkg/dashboards/dashboards_widgets_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,87 @@ func TestIntegrationDashboard_Billboard(t *testing.T) {
assert.Equal(t, 0, len(delRes.Errors))
assert.Equal(t, DashboardDeleteResultStatusTypes.SUCCESS, delRes.Status)
}

// TestIntegrationDashboard_EmptyPage tests creating a dashboard with a page comprising no widgets
func TestIntegrationDashboard_EmptyPage(t *testing.T) {
t.Parallel()

testAccountID, err := mock.GetTestAccountID()
if err != nil {
t.Skipf("%s", err)
}

client := newIntegrationTestClient(t)

dashboardName := "newrelic-client-go-test-dashboard-empty-pages" + mock.RandSeq(5)
dashboardInput := DashboardInput{
Description: "newrelic-client-go-test-dashboard-description",
Name: dashboardName,
Permissions: entities.DashboardPermissionsTypes.PUBLIC_READ_WRITE,
Pages: []DashboardPageInput{{
Name: "Test Page",
Widgets: []DashboardWidgetInput{},
}},
}

// Test: Create Dashboard
result, err := client.DashboardCreate(testAccountID, dashboardInput)

require.NoError(t, err)
require.NotNil(t, result)
assert.Equal(t, 0, len(result.Errors))
require.NotNil(t, result.EntityResult.GUID)

dashGUID := result.EntityResult.GUID

// Test: Get Dashboard
dash, err := client.GetDashboardEntity(dashGUID)
require.NoError(t, err)
require.NotNil(t, dash)

assert.Equal(t, dashGUID, dash.GUID)
assert.Equal(t, dashboardInput.Description, dash.Description)
assert.Equal(t, dashboardInput.Name, dash.Name)
assert.Equal(t, dashboardInput.Permissions, dash.Permissions)

// Test: Update Dashboard
updatedDashboard := DashboardInput{
Name: dash.Name,
Permissions: dash.Permissions,
Pages: []DashboardPageInput{
{
Name: dash.Pages[0].Name,
Widgets: []DashboardWidgetInput{
{
Title: "Test BillboardText Widget",
Configuration: DashboardWidgetConfigurationInput{
Billboard: &DashboardBillboardWidgetConfigurationInput{
NRQLQueries: []DashboardWidgetNRQLQueryInput{
{
AccountID: testAccountID,
Query: "FROM Metric SELECT 1",
},
},
},
},
},
},
},
{
Name: "Test Page Two",
Widgets: []DashboardWidgetInput{},
},
},
}

upDash, err := client.DashboardUpdate(updatedDashboard, dashGUID)
require.NoError(t, err)
require.NotNil(t, upDash)

//// Test: Delete Dashboard
delRes, err := client.DashboardDelete(dashGUID)
require.NoError(t, err)
require.NotNil(t, delRes)
assert.Equal(t, 0, len(delRes.Errors))
assert.Equal(t, DashboardDeleteResultStatusTypes.SUCCESS, delRes.Status)
}
14 changes: 12 additions & 2 deletions pkg/dashboards/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,13 @@ type DashboardPageInput struct {
GUID common.EntityGUID `json:"guid,omitempty"`
// The name of the page.
Name string `json:"name"`

// NOTE: The JSON description of the following attribute, "Widgets" has been modified manually
// (removal of "omitempty") to facilitate creating pages with no widgets (empty pages).
// Please DO NOT regenerate/modify this attribute and its datatype via Tutone (which would add "omitempty" back).

// A nested block of all widgets belonging to the page.
Widgets []DashboardWidgetInput `json:"widgets,omitempty"`
Widgets []DashboardWidgetInput `json:"widgets"`
}

// DashboardPieWidgetConfigurationInput - Configuration for visualization type 'viz.pie'. Learn more about [pie](https://docs.newrelic.com/docs/apis/nerdgraph/examples/create-widgets-dashboards-api/#pie) widget.
Expand Down Expand Up @@ -312,8 +317,13 @@ type DashboardUpdatePageInput struct {
Description string `json:"description,omitempty"`
// Page name.
Name string `json:"name"`

// NOTE: The JSON description of the following attribute, "Widgets" has been modified manually
// (removal of "omitempty") to facilitate creating pages with no widgets (empty pages).
// Please DO NOT regenerate/modify this attribute and its datatype via Tutone (which would add "omitempty" back).

// Page widgets.
Widgets []DashboardWidgetInput `json:"widgets,omitempty"`
Widgets []DashboardWidgetInput `json:"widgets"`
}

// DashboardUpdatePageResult - Result of updatePage operation.
Expand Down

0 comments on commit 7ba7df9

Please sign in to comment.