11package gapi
22
33import (
4+ "strings"
45 "testing"
56
67 "github.com/gobs/pretty"
@@ -29,8 +30,7 @@ const (
2930 }
3031 }`
3132
32- getDashboardsJSON = `[
33- {
33+ getDashboardsJSON = `{
3434 "id": 1,
3535 "uid": "RGAPB1cZz",
3636 "title": "Grafana Stats",
@@ -40,8 +40,7 @@ const (
4040 "type": "dash-db",
4141 "tags": [],
4242 "isStarred": false
43- }
44- ]`
43+ }`
4544)
4645
4746func TestDashboardCreateAndUpdate (t * testing.T ) {
@@ -142,20 +141,32 @@ func TestDashboardDelete(t *testing.T) {
142141}
143142
144143func TestDashboards (t * testing.T ) {
145- client := gapiTestTools (t , 200 , getDashboardsJSON )
144+ mockData := strings .Repeat (getDashboardsJSON + "," , 1000 ) // make 1000 dashboards.
145+ mockData = "[" + mockData [:len (mockData )- 1 ] + "]" // remove trailing comma; make a json list.
146+
147+ // This creates 1000 + 1000 + 1 (2001, 3 calls) worth of dashboards.
148+ client := gapiTestToolsFromCalls (t , []mockServerCall {
149+ {200 , mockData },
150+ {200 , mockData },
151+ {200 , "[" + getDashboardsJSON + "]" },
152+ })
153+
154+ const dashCount = 2001
146155
147156 dashboards , err := client .Dashboards ()
148157 if err != nil {
149158 t .Fatal (err )
150159 }
151160
152- t .Log (pretty .PrettyFormat (dashboards ))
153-
154- if len (dashboards ) != 1 {
155- t .Error ("Length of returned dashboards should be 1" )
161+ if len (dashboards ) != dashCount {
162+ t .Errorf ("Length of returned dashboards should be %d" , dashCount )
156163 }
157164
158165 if dashboards [0 ].ID != 1 || dashboards [0 ].Title != "Grafana Stats" {
159166 t .Error ("Not correctly parsing returned dashboards." )
160167 }
168+
169+ if dashboards [dashCount - 1 ].ID != 1 || dashboards [dashCount - 1 ].Title != "Grafana Stats" {
170+ t .Error ("Not correctly parsing returned dashboards." )
171+ }
161172}
0 commit comments