You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2021/10/11 14:38:46 UTC
[trafficcontrol] branch master updated: Add TO Client API for
Delivery Services Required Capabilities (#6233)
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 5985a56 Add TO Client API for Delivery Services Required Capabilities (#6233)
5985a56 is described below
commit 5985a56a251e3f3da9a5659ab05b89e2bdb0f405
Author: dmohan001c <de...@comcast.com>
AuthorDate: Mon Oct 11 20:08:24 2021 +0530
Add TO Client API for Delivery Services Required Capabilities (#6233)
* added test for pagination support
* added newline at end of file
---
.../deliveryservices_required_capabilities_test.go | 70 ++++++++++++++++++++++
traffic_ops/testing/api/v4/tc-fixtures.json | 63 +++++++++++++------
.../deliveryservices_required_capabilities.go | 1 +
3 files changed, 116 insertions(+), 18 deletions(-)
diff --git a/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go b/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go
index 3cf51e2..1e304ef 100644
--- a/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go
+++ b/traffic_ops/testing/api/v4/deliveryservices_required_capabilities_test.go
@@ -19,6 +19,7 @@ import (
"fmt"
"net/http"
"net/url"
+ "reflect"
"strconv"
"strings"
"testing"
@@ -41,6 +42,7 @@ func TestDeliveryServicesRequiredCapabilities(t *testing.T) {
header = make(map[string][]string)
header.Set(rfc.IfModifiedSince, time)
GetTestDeliveryServicesRequiredCapabilitiesIMSAfterChange(t, header)
+ GetTestPaginationSupportDsrc(t)
})
}
@@ -645,3 +647,71 @@ func helperGetDeliveryServiceID(t *testing.T, xmlID *string) *int {
}
return ds.Response[0].ID
}
+
+func GetTestPaginationSupportDsrc(t *testing.T) {
+ opts := client.NewRequestOptions()
+ opts.QueryParameters.Set("orderby", "requiredCapability")
+ resp, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ if err != nil {
+ t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities: %v - alerts: %+v", err, resp.Alerts)
+ }
+ dsrc := resp.Response
+ if len(dsrc) < 3 {
+ t.Fatalf("Need at least 3 DeliveryServicesRequiredCapabilities in Traffic Ops to test pagination support, found: %d", len(dsrc))
+ }
+ opts.QueryParameters.Set("limit", "1")
+ dsrcWithLimit, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ if err != nil {
+ t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities with Limit: %v - alerts: %+v", err, dsrcWithLimit.Alerts)
+ }
+ if !reflect.DeepEqual(dsrc[:1], dsrcWithLimit.Response) {
+ t.Error("expected GET DeliveryServicesRequiredCapabilities with limit = 1 to return first result")
+ }
+
+ opts.QueryParameters.Set("offset", "1")
+ dsrcWithOffset, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ if err != nil {
+ t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities with Limit and Offset: %v - alerts: %+v", err, dsrcWithOffset.Alerts)
+ }
+ if !reflect.DeepEqual(dsrc[1:2], dsrcWithOffset.Response) {
+ t.Error("expected GET DeliveryServicesRequiredCapabilities with limit = 1, offset = 1 to return second result")
+ }
+
+ opts.QueryParameters.Del("offset")
+ opts.QueryParameters.Set("page", "2")
+ dsrcWithPage, _, err := TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ if err != nil {
+ t.Fatalf("cannot Get DeliveryServicesRequiredCapabilities with Limit and Page: %v - alerts: %+v", err, dsrcWithPage.Alerts)
+ }
+ if !reflect.DeepEqual(dsrc[1:2], dsrcWithPage.Response) {
+ t.Error("expected GET DeliveryServicesRequiredCapabilities with limit = 1, page = 2 to return second result")
+ }
+
+ opts.QueryParameters = url.Values{}
+ opts.QueryParameters.Set("limit", "-2")
+ resp, _, err = TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ if err == nil {
+ t.Error("expected GET DeliveryServicesRequiredCapabilities to return an error when limit is not bigger than -1")
+ } else if !alertsHaveError(resp.Alerts.Alerts, "must be bigger than -1") {
+ t.Errorf("expected GET DeliveryServicesRequiredCapabilities to return an error for limit is not bigger than -1, actual error: %v - alerts: %+v", err, resp.Alerts)
+ }
+
+ opts.QueryParameters.Set("limit", "1")
+ opts.QueryParameters.Set("offset", "0")
+ resp, _, err = TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ if err == nil {
+ t.Error("expected GET DeliveryServicesRequiredCapabilities to return an error when offset is not a positive integer")
+ } else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+ t.Errorf("expected GET DeliveryServicesRequiredCapabilities to return an error for offset is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+ }
+
+ opts.QueryParameters = url.Values{}
+ opts.QueryParameters.Set("limit", "1")
+ opts.QueryParameters.Set("page", "0")
+ resp, _, err = TOSession.GetDeliveryServicesRequiredCapabilities(opts)
+ if err == nil {
+ t.Error("expected GET DeliveryServicesRequiredCapabilities to return an error when page is not a positive integer")
+ } else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+ t.Errorf("expected GET DeliveryServicesRequiredCapabilities to return an error for page is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+ }
+}
diff --git a/traffic_ops/testing/api/v4/tc-fixtures.json b/traffic_ops/testing/api/v4/tc-fixtures.json
index 2844182..f4514d1 100644
--- a/traffic_ops/testing/api/v4/tc-fixtures.json
+++ b/traffic_ops/testing/api/v4/tc-fixtures.json
@@ -484,7 +484,11 @@
"cdnName": "cdn1",
"ccrDnsTtl": 3600,
"checkPath": "",
- "consistentHashQueryParams": ["fmt", "limit", "somethingelse"],
+ "consistentHashQueryParams": [
+ "fmt",
+ "limit",
+ "somethingelse"
+ ],
"deepCachingType": "NEVER",
"displayName": "d s 1",
"dnsBypassCname": null,
@@ -675,7 +679,11 @@
"cdnName": "cdn1",
"ccrDnsTtl": 3600,
"checkPath": "",
- "consistentHashQueryParams": ["a", "b", "c"],
+ "consistentHashQueryParams": [
+ "a",
+ "b",
+ "c"
+ ],
"consistentHashRegex": "foo",
"deepCachingType": "ALWAYS",
"displayName": "ds-test-minor-versions",
@@ -1720,25 +1728,25 @@
"dsName": "ds1",
"typeName": "HOST_REGEXP",
"setNumber": 1,
- "pattern" : ".*"
+ "pattern": ".*"
},
{
"dsName": "ds1",
"typeName": "HOST_REGEXP",
"setNumber": 2,
- "pattern" : "\\d+"
+ "pattern": "\\d+"
},
{
"dsName": "ds2",
"typeName": "HOST_REGEXP",
"setNumber": 1,
- "pattern" : ".*"
+ "pattern": ".*"
},
{
"dsName": "ds1",
"typeName": "HOST_REGEXP",
"setNumber": 3,
- "pattern" : ""
+ "pattern": ""
}
],
"deliveryservicesRequiredCapabilities": [
@@ -1838,10 +1846,10 @@
"ipAddress": "1.2.3.4",
"ip6Address": "dead:beef:cafe::42",
"port": 1234,
- "Profile" : "ATS_EDGE_TIER_CACHE",
+ "Profile": "ATS_EDGE_TIER_CACHE",
"protocol": "http",
"tenant": "tenant1",
- "isPrimary" : true
+ "isPrimary": true
},
{
"name": "origin2",
@@ -5039,15 +5047,22 @@
},
{
"cachegroup": "parentCachegroup",
- "parents": [0]
+ "parents": [
+ 0
+ ]
},
{
"cachegroup": "secondaryCachegroup",
- "parents": [0]
+ "parents": [
+ 0
+ ]
},
{
"cachegroup": "cachegroup3",
- "parents": [1, 2]
+ "parents": [
+ 1,
+ 2
+ ]
}
]
},
@@ -5229,11 +5244,15 @@
},
{
"cachegroup": "dtrc2",
- "parents": [0]
+ "parents": [
+ 0
+ ]
},
{
"cachegroup": "dtrc3",
- "parents": [0]
+ "parents": [
+ 0
+ ]
}
]
},
@@ -5247,11 +5266,15 @@
},
{
"cachegroup": "dtrc1",
- "parents": [0]
+ "parents": [
+ 0
+ ]
},
{
"cachegroup": "dtrc2",
- "parents": [1]
+ "parents": [
+ 1
+ ]
}
]
},
@@ -5265,11 +5288,15 @@
},
{
"cachegroup": "dtrc2",
- "parents": [0]
+ "parents": [
+ 0
+ ]
},
{
"cachegroup": "dtrc3",
- "parents": [0]
+ "parents": [
+ 0
+ ]
}
]
},
@@ -5653,7 +5680,7 @@
"ttl": 2160
},
{
- "deliveryService": "ds2",
+ "deliveryService": "ds2",
"regex": "\\/some-path?.+\\.jpg",
"startTime": "2100-06-19T13:57:51-06:00",
"ttl": 2.1
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices_required_capabilities.go b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices_required_capabilities.go
index 20d26a8..0434951 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices_required_capabilities.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices_required_capabilities.go
@@ -202,6 +202,7 @@ func (rc *RequiredCapability) getCapabilities(h http.Header, tenantIDs []int, us
var runSecond bool
var results []tc.DeliveryServicesRequiredCapability
where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(rc.APIInfo().Params, rc.ParamColumns())
+
if len(errs) > 0 {
return nil, util.JoinErrs(errs), nil, http.StatusBadRequest, nil
}