This is an automated email from the ASF dual-hosted git repository.
zrhoffman 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 710e518 Added tests for Cachegroup and Deliveryservice Pagination
(#5668)
710e518 is described below
commit 710e5182117b23a1465afa36d5ba214fdb72f36f
Author: dmohan001c <[email protected]>
AuthorDate: Thu Mar 25 20:43:08 2021 +0530
Added tests for Cachegroup and Deliveryservice Pagination (#5668)
* added test case for CacheGroup Pagination functionalites
* added testcase for deliveryservice page functionality
* Fixed formatting issues
* replcaed the deprecated function with new one
* formatted the code using go fmt
---
traffic_ops/testing/api/v4/cachegroups_test.go | 66 ++++++++++++++++++++++
.../testing/api/v4/deliveryservices_test.go | 65 +++++++++++++++++++++
2 files changed, 131 insertions(+)
diff --git a/traffic_ops/testing/api/v4/cachegroups_test.go
b/traffic_ops/testing/api/v4/cachegroups_test.go
index fe34213..edadef5 100644
--- a/traffic_ops/testing/api/v4/cachegroups_test.go
+++ b/traffic_ops/testing/api/v4/cachegroups_test.go
@@ -20,6 +20,7 @@ import (
"net/http"
"net/url"
"reflect"
+ "strings"
"testing"
"time"
@@ -50,6 +51,7 @@ func TestCacheGroups(t *testing.T) {
etag := rfc.ETag(currentTime)
header.Set(rfc.IfMatch, etag)
UpdateTestCacheGroupsWithHeaders(t, header)
+ VerifyPaginationSupportCg(t)
})
}
@@ -584,3 +586,67 @@ func CheckCacheGroupsAuthentication(t *testing.T) {
t.Error(fmt.Errorf(errFormat, "DeleteCacheGroupByID"))
}
}
+
+func VerifyPaginationSupportCg(t *testing.T) {
+ qparams := url.Values{}
+ qparams.Set("orderby", "id")
+ cachegroup, _, err :=
TOSession.GetCacheGroupsByQueryParamsWithHdr(qparams, nil)
+ if err != nil {
+ t.Fatalf("cannot GET Cachegroup: %v", err)
+ }
+
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ cachegroupWithLimit, _, err :=
TOSession.GetCacheGroupsByQueryParamsWithHdr(qparams, nil)
+ if !reflect.DeepEqual(cachegroup[:1], cachegroupWithLimit) {
+ t.Error("expected GET Cachegroups with limit = 1 to return
first result")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ qparams.Set("offset", "1")
+ cachegroupsWithOffset, _, err :=
TOSession.GetCacheGroupsByQueryParamsWithHdr(qparams, nil)
+ if !reflect.DeepEqual(cachegroup[1:2], cachegroupsWithOffset) {
+ t.Error("expected GET cachegroup with limit = 1, offset = 1 to
return second result")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ qparams.Set("page", "2")
+ cachegroupWithPage, _, err :=
TOSession.GetCacheGroupsByQueryParamsWithHdr(qparams, nil)
+ if !reflect.DeepEqual(cachegroup[1:2], cachegroupWithPage) {
+ t.Error("expected GET cachegroup with limit = 1, page = 2 to
return second result")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("limit", "-2")
+ _, _, err = TOSession.GetCacheGroupsByQueryParamsWithHdr(qparams, nil)
+ if err == nil {
+ t.Error("expected GET cachegroup 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 cachegroup 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.GetCacheGroupsByQueryParamsWithHdr(qparams, nil)
+ if err == nil {
+ t.Error("expected GET cachegroup 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 cachegroup 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.GetCacheGroupsByQueryParamsWithHdr(qparams, nil)
+ if err == nil {
+ t.Error("expected GET cachegroup 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 cachegroup to return an error for page
is not a positive integer, actual error: " + err.Error())
+ }
+}
diff --git a/traffic_ops/testing/api/v4/deliveryservices_test.go
b/traffic_ops/testing/api/v4/deliveryservices_test.go
index 4420919..a0b09a0 100644
--- a/traffic_ops/testing/api/v4/deliveryservices_test.go
+++ b/traffic_ops/testing/api/v4/deliveryservices_test.go
@@ -65,6 +65,7 @@ func TestDeliveryServices(t *testing.T) {
etag := rfc.ETag(currentTime)
header.Set(rfc.IfMatch, etag)
UpdateTestDeliveryServicesWithHeaders(t, header)
+ VerifyPaginationSupportDS(t)
})
}
@@ -1171,3 +1172,67 @@ func DeliveryServiceTenancyTest(t *testing.T) {
t.Error("expected tenant4user to be unable to create a
deliveryservice outside of its tenant")
}
}
+
+func VerifyPaginationSupportDS(t *testing.T) {
+ qparams := url.Values{}
+ qparams.Set("orderby", "id")
+ deliveryservice, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+ if err != nil {
+ t.Fatalf("cannot GET DeliveryService: %v", err)
+ }
+
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ deliveryserviceWithLimit, _, err :=
TOSession.GetDeliveryServicesV4(nil, qparams)
+ if !reflect.DeepEqual(deliveryservice[:1], deliveryserviceWithLimit) {
+ t.Error("expected GET deliveryservice with limit = 1 to return
first result")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ qparams.Set("offset", "1")
+ deliveryserviceWithOffset, _, err :=
TOSession.GetDeliveryServicesV4(nil, qparams)
+ if !reflect.DeepEqual(deliveryservice[1:2], deliveryserviceWithOffset) {
+ t.Error("expected GET deliveryservice with limit = 1, offset =
1 to return second result")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("orderby", "id")
+ qparams.Set("limit", "1")
+ qparams.Set("page", "2")
+ deliveryserviceWithPage, _, err := TOSession.GetDeliveryServicesV4(nil,
qparams)
+ if !reflect.DeepEqual(deliveryservice[1:2], deliveryserviceWithPage) {
+ t.Error("expected GET cachegroup with limit = 1, page = 2 to
return second result")
+ }
+
+ qparams = url.Values{}
+ qparams.Set("limit", "-2")
+ _, _, err = TOSession.GetDeliveryServicesV4(nil, qparams)
+ if err == nil {
+ t.Error("expected GET deliveryservice 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 deliveryservice 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.GetDeliveryServicesV4(nil, qparams)
+ if err == nil {
+ t.Error("expected GET deliveryservice 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 deliveryservice 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.GetDeliveryServicesV4(nil, qparams)
+ if err == nil {
+ t.Error("expected GET deliveryservice 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 deliveryservice to return an error for
page is not a positive integer, actual error: " + err.Error())
+ }
+}