Skip to content

Commit d7b2f43

Browse files
committed
chore: moved tests and clean up code
1 parent 74869e5 commit d7b2f43

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

bluemix/configuration/core_config/bx_config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ func (c *bxConfig) ClearPaginationURLs() {
770770
})
771771
}
772772

773-
func (c *bxConfig) AddPaginationURL(index int, url string) error {
773+
func (c *bxConfig) AddPaginationURL(index int, url string) {
774774
urls := c.PaginationURLs()
775775

776776
urls = append(urls, models.PaginationURL{
@@ -781,7 +781,6 @@ func (c *bxConfig) AddPaginationURL(index int, url string) error {
781781
// sort by last index for easier retrieval
782782
sort.Sort(models.ByLastIndex(urls))
783783
c.SetPaginationURLs(urls)
784-
return nil
785784
}
786785

787786
func (c *bxConfig) PaginationURLs() (paginationURLs []models.PaginationURL) {

bluemix/configuration/core_config/bx_config_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ func TestPaginationURLs(t *testing.T) {
476476
paginationURLs := config.PaginationURLs()
477477
assert.Empty(t, paginationURLs)
478478

479-
// update session
480479
expected := []models.PaginationURL{
481480
{
482481
NextURL: "https://api.example.com?token=dd3784000d9744acb2a23ad121a7bb4b",
@@ -494,6 +493,40 @@ func TestPaginationURLs(t *testing.T) {
494493

495494
}
496495

496+
func TestAddPaginationURL(t *testing.T) {
497+
config := prepareConfigForCLI(`{}`, t)
498+
assert := assert.New(t)
499+
unsortedUrls := []models.PaginationURL{
500+
{
501+
NextURL: "/v2/example.com/stuff?limit=200",
502+
LastIndex: 200,
503+
},
504+
{
505+
NextURL: "/v2/example.com/stuff?limit=100",
506+
LastIndex: 50,
507+
},
508+
{
509+
NextURL: "/v2/example.com/stuff?limit=100",
510+
LastIndex: 100,
511+
},
512+
}
513+
514+
for _, p := range unsortedUrls {
515+
config.AddPaginationURL(p.LastIndex, p.NextURL)
516+
}
517+
518+
// expect url to be sorted in ascending order by LastIndex
519+
sortedUrls := config.PaginationURLs()
520+
521+
assert.Equal(3, len(sortedUrls))
522+
assert.Equal(sortedUrls[0].LastIndex, unsortedUrls[1].LastIndex)
523+
assert.Equal(sortedUrls[0].NextURL, unsortedUrls[1].NextURL)
524+
assert.Equal(sortedUrls[1].LastIndex, unsortedUrls[2].LastIndex)
525+
assert.Equal(sortedUrls[1].NextURL, unsortedUrls[2].NextURL)
526+
assert.Equal(sortedUrls[2].LastIndex, unsortedUrls[0].LastIndex)
527+
assert.Equal(sortedUrls[2].NextURL, unsortedUrls[0].NextURL)
528+
}
529+
497530
func checkUsageStats(enabled bool, timeStampExist bool, config core_config.Repository, t *testing.T) {
498531
assert.Equal(t, config.UsageStatsEnabled(), enabled)
499532
assert.Equal(t, config.UsageStatsEnabledLastUpdate().IsZero(), !timeStampExist)

bluemix/configuration/core_config/repository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type Repository interface {
128128

129129
SetPaginationURLs(paginationURLs []models.PaginationURL)
130130
ClearPaginationURLs()
131-
AddPaginationURL(lastIndex int, nextURL string) error
131+
AddPaginationURL(lastIndex int, nextURL string)
132132
PaginationURLs() []models.PaginationURL
133133
}
134134

@@ -377,8 +377,8 @@ func (c repository) PaginationURLs() []models.PaginationURL {
377377
return c.bxConfig.PaginationURLs()
378378
}
379379

380-
func (c repository) AddPaginationURL(index int, url string) error {
381-
return c.bxConfig.AddPaginationURL(index, url)
380+
func (c repository) AddPaginationURL(index int, url string) {
381+
c.bxConfig.AddPaginationURL(index, url)
382382
}
383383

384384
func (c repository) SetPaginationURLs(paginationURLs []models.PaginationURL) {

common/rest/request_test.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -179,33 +179,3 @@ func TestCachedPaginationNextURL(t *testing.T) {
179179
})
180180
}
181181
}
182-
183-
func TestAddPaginationURL(t *testing.T) {
184-
config := testhelpers.NewFakeCoreConfig()
185-
assert := assert.New(t)
186-
unsortedUrls := []models.PaginationURL{
187-
{
188-
NextURL: "/v2/example.com/stuff?limit=200",
189-
LastIndex: 200,
190-
},
191-
{
192-
NextURL: "/v2/example.com/stuff?limit=100",
193-
LastIndex: 100,
194-
},
195-
}
196-
197-
var err error
198-
for _, p := range unsortedUrls {
199-
err = config.AddPaginationURL(p.LastIndex, p.NextURL)
200-
assert.Nil(err)
201-
}
202-
203-
// expect url to be sorted in ascending order by LastIndex
204-
sortedUrls := config.PaginationURLs()
205-
206-
assert.Equal(2, len(sortedUrls))
207-
assert.Equal(sortedUrls[0].LastIndex, unsortedUrls[1].LastIndex)
208-
assert.Equal(sortedUrls[0].NextURL, unsortedUrls[1].NextURL)
209-
assert.Equal(sortedUrls[1].LastIndex, unsortedUrls[0].LastIndex)
210-
assert.Equal(sortedUrls[1].NextURL, unsortedUrls[0].NextURL)
211-
}

0 commit comments

Comments
 (0)