This is an automated email from the ASF dual-hosted git repository.
ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 45baf82 Add TO Client API for Physical Location Automation (#5822)
45baf82 is described below
commit 45baf8206f57f039ab5ef6a2bac5f4cb32ad028c
Author: dmohan001c <[email protected]>
AuthorDate: Tue May 11 19:57:09 2021 +0530
Add TO Client API for Physical Location Automation (#5822)
* added test case for CacheGroup Pagination functionalites
* Update cachegroups_test.go
* added tests for phyical location pagination functionality
---
traffic_ops/testing/api/v4/phys_locations_test.go | 89 ++++++++++++++++++++++-
1 file changed, 87 insertions(+), 2 deletions(-)
diff --git a/traffic_ops/testing/api/v4/phys_locations_test.go
b/traffic_ops/testing/api/v4/phys_locations_test.go
index 1440448..d8dbb51 100644
--- a/traffic_ops/testing/api/v4/phys_locations_test.go
+++ b/traffic_ops/testing/api/v4/phys_locations_test.go
@@ -18,7 +18,9 @@ package v4
import (
"net/http"
"net/url"
+ "reflect"
"sort"
+ "strings"
"testing"
"time"
@@ -46,6 +48,7 @@ func TestPhysLocations(t *testing.T) {
etag := rfc.ETag(currentTime)
header.Set(rfc.IfMatch, etag)
UpdateTestPhysLocationsWithHeaders(t, header)
+ GetTestPaginationSupportPhysLocation(t)
})
}
@@ -127,9 +130,8 @@ func CreateTestPhysLocations(t *testing.T) {
}
func SortTestPhysLocations(t *testing.T) {
- var header http.Header
var sortedList []string
- resp, _, err := TOSession.GetPhysLocations(nil, header)
+ resp, _, err := TOSession.GetPhysLocations(nil, nil)
if err != nil {
t.Fatalf("Expected no error, but got %v", err.Error())
}
@@ -238,3 +240,86 @@ func DeleteTestPhysLocations(t *testing.T) {
}
}
}
+
+func GetTestPaginationSupportPhysLocation(t *testing.T) {
+ qparams := url.Values{}
+ qparams.Set("orderby", "id")
+ physlocations, _, err := TOSession.GetPhysLocations(qparams, nil)
+ if err != nil {
+ t.Errorf("cannot GET Physical Locations: %v", err)
+ }
+
+ if len(physlocations) > 0 {
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ physlocationsWithLimit, _, err :=
TOSession.GetPhysLocations(qparams, nil)
+ if err == nil {
+ if !reflect.DeepEqual(physlocations[:1],
physlocationsWithLimit) {
+ t.Error("expected GET PhysLocation with limit =
1 to return first result")
+ }
+ } else {
+ t.Error("Error in getting PhysLocation by limit")
+ }
+ if len(physlocations) > 1 {
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ qparams.Set("offset", "1")
+ physlocationsWithOffset, _, err :=
TOSession.GetPhysLocations(qparams, nil)
+ if err == nil {
+ if !reflect.DeepEqual(physlocations[1:2],
physlocationsWithOffset) {
+ t.Error("expected GET PhysLocation with
limit = 1, offset = 1 to return second result")
+ }
+ } else {
+ t.Error("Error in getting PhysLocation by limit
and offset")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ qparams.Set("page", "2")
+ physlocationsWithPage, _, err :=
TOSession.GetPhysLocations(qparams, nil)
+ if err == nil {
+ if !reflect.DeepEqual(physlocations[1:2],
physlocationsWithPage) {
+ t.Error("expected GET PhysLocation with
limit = 1, page = 2 to return second result")
+ }
+ } else {
+ t.Error("Error in getting PhysLocation by limit
and page")
+ }
+ } else {
+ t.Errorf("only one PhysLocation found, so offset
functionality can't test")
+ }
+ } else {
+ t.Errorf("No PhysLocation found to check pagination")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("limit", "-2")
+ _, _, err = TOSession.GetPhysLocations(qparams, nil)
+ if err == nil {
+ t.Error("expected GET PhysLocation to return an error when
limit is not bigger than -1")
+ } else if !strings.Contains(err.Error(), "must be bigger than -1") {
+ t.Errorf("expected GET PhysLocation to return an error for
limit is not bigger than -1, actual error: " + err.Error())
+ }
+
+ qparams = url.Values{}
+ qparams.Set("limit", "1")
+ qparams.Set("offset", "0")
+ _, _, err = TOSession.GetPhysLocations(qparams, nil)
+ if err == nil {
+ t.Error("expected GET PhysLocation to return an error when
offset is not a positive integer")
+ } else if !strings.Contains(err.Error(), "must be a positive integer") {
+ t.Errorf("expected GET PhysLocation to return an error for
offset is not a positive integer, actual error: " + err.Error())
+ }
+
+ qparams = url.Values{}
+ qparams.Set("limit", "1")
+ qparams.Set("page", "0")
+ _, _, err = TOSession.GetPhysLocations(qparams, nil)
+ if err == nil {
+ t.Error("expected GET PhysLocation to return an error when page
is not a positive integer")
+ } else if !strings.Contains(err.Error(), "must be a positive integer") {
+ t.Errorf("expected GET PhysLocation to return an error for page
is not a positive integer, actual error: " + err.Error())
+ }
+}