Skip to content

Commit 7d18154

Browse files
Adding the ability to search for built in content only (#257)
1 parent 8a08f36 commit 7d18154

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

dashboardgroup.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,27 @@ func (c *Client) SearchDashboardGroups(ctx context.Context, limit int, name stri
115115

116116
return finalDashboardGroups, err
117117
}
118+
119+
func (c *Client) ListBuiltInDashboardGroups(ctx context.Context, limit int, offset int) (*dashboard_group.SearchResult, error) {
120+
params := url.Values{}
121+
params.Add("limit", strconv.Itoa(limit))
122+
params.Add("offset", strconv.Itoa(offset))
123+
params.Add("excludeCustom", "true")
124+
125+
resp, err := c.doRequest(ctx, "GET", DashboardGroupAPIURL, params, nil)
126+
if err != nil {
127+
return nil, err
128+
}
129+
defer resp.Body.Close()
130+
131+
if err = newResponseError(resp, http.StatusOK); err != nil {
132+
return nil, err
133+
}
134+
135+
finalDashboardGroups := &dashboard_group.SearchResult{}
136+
137+
err = json.NewDecoder(resp.Body).Decode(finalDashboardGroups)
138+
_, _ = io.Copy(io.Discard, resp.Body)
139+
140+
return finalDashboardGroups, err
141+
}

dashboardgroup_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,20 @@ func TestValidateDashboardGroupWithModeBad(t *testing.T) {
193193
Name: "string",
194194
}, "INVALID MODE")
195195
assert.Error(t, err, "Should have gotten an error for invalid mode")
196+
197+
}
198+
199+
func TestListBuiltInDashboardGroups(t *testing.T) {
200+
teardown := setup()
201+
defer teardown()
202+
203+
params := url.Values{}
204+
params.Add("limit", strconv.Itoa(10))
205+
params.Add("offset", strconv.Itoa(0))
206+
params.Add("excludeCustom", "true")
207+
mux.HandleFunc("/v2/dashboardgroup", verifyRequest(t, "GET", true, http.StatusOK, params, "dashboardgroup/search_success.json"))
208+
209+
results, err := client.ListBuiltInDashboardGroups(context.Background(), 10, 0)
210+
assert.NoError(t, err, "Unexpected error listing built-in dashboard groups")
211+
assert.Equal(t, int32(1), results.Count, "Incorrect number of built-in dashboard groups")
196212
}

0 commit comments

Comments
 (0)