Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"
"strconv"
"strings"
"testing"
Expand All @@ -41,6 +42,7 @@ func TestDeliveryServicesRequiredCapabilities(t *testing.T) {
header = make(map[string][]string)
header.Set(rfc.IfModifiedSince, time)
GetTestDeliveryServicesRequiredCapabilitiesIMSAfterChange(t, header)
GetTestPaginationSupportDsrc(t)
})
}

Expand Down Expand Up @@ -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)
}
}
63 changes: 45 additions & 18 deletions traffic_ops/testing/api/v4/tc-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1593,25 +1601,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": [
Expand Down Expand Up @@ -1711,10 +1719,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",
Expand Down Expand Up @@ -4916,15 +4924,22 @@
},
{
"cachegroup": "parentCachegroup",
"parents": [0]
"parents": [
0
]
},
{
"cachegroup": "secondaryCachegroup",
"parents": [0]
"parents": [
0
]
},
{
"cachegroup": "cachegroup3",
"parents": [1, 2]
"parents": [
1,
2
]
}
]
},
Expand Down Expand Up @@ -5106,11 +5121,15 @@
},
{
"cachegroup": "dtrc2",
"parents": [0]
"parents": [
0
]
},
{
"cachegroup": "dtrc3",
"parents": [0]
"parents": [
0
]
}
]
},
Expand All @@ -5124,11 +5143,15 @@
},
{
"cachegroup": "dtrc1",
"parents": [0]
"parents": [
0
]
},
{
"cachegroup": "dtrc2",
"parents": [1]
"parents": [
1
]
}
]
},
Expand All @@ -5142,11 +5165,15 @@
},
{
"cachegroup": "dtrc2",
"parents": [0]
"parents": [
0
]
},
{
"cachegroup": "dtrc3",
"parents": [0]
"parents": [
0
]
}
]
},
Expand Down Expand Up @@ -5534,7 +5561,7 @@
"ttl": 2160
},
{
"deliveryService": "ds2",
"deliveryService": "ds2",
"regex": "\\/some-path?.+\\.jpg",
"startTime": "2100-06-19T13:57:51-06:00",
"ttl": 2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down