zrhoffman commented on code in PR #7151:
URL: https://github.com/apache/trafficcontrol/pull/7151#discussion_r1002127862
##########
traffic_ops/testing/api/v5/deliveryservices_required_capabilities_test.go:
##########
@@ -79,119 +83,123 @@ func TestDeliveryServicesRequiredCapabilities(t
*testing.T) {
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
validateDSRCPagination("page")),
},
"BAD REQUEST when INVALID LIMIT parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"-2"}}},
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"-2"}}},
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when INVALID OFFSET parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "offset":
{"0"}}},
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "offset":
{"0"}}},
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when INVALID PAGE parameter": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "page":
{"0"}}},
- Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{QueryParameters: url.Values{"limit": {"1"}, "page":
{"0"}}},
+ Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+ },
+ "OK when CHANGES made": {
+ ClientSession: TOSession,
+ RequestOpts:
client.RequestOptions{Header: http.Header{rfc.IfModifiedSince:
{currentTimeRFC}}},
+ Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
},
"POST": {
"BAD REQUEST when REASSIGNING REQUIRED
CAPABILITY to DELIVERY SERVICE": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "deliveryServiceID":
GetDeliveryServiceId(t, "ds1")(),
- "requiredCapability": "foo",
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "ds1")()),
+ RequiredCapability:
util.StrPtr("foo"),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when SERVERS DONT have
CAPABILITY": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "deliveryServiceID":
GetDeliveryServiceId(t, "test-ds-server-assignments")(),
- "requiredCapability": "disk",
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "test-ds-server-assignments")()),
+ RequiredCapability:
util.StrPtr("disk"),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when DELIVERY SERVICE HAS TOPOLOGY
where SERVERS DONT have CAPABILITY": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "deliveryServiceID":
GetDeliveryServiceId(t, "ds-top-req-cap")(),
- "requiredCapability": "bar",
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "ds-top-req-cap")()),
+ RequiredCapability:
util.StrPtr("bar"),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when DELIVERY SERVICE ID EMPTY": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "requiredCapability": "bar",
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ RequiredCapability:
util.StrPtr("bar"),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"BAD REQUEST when REQUIRED CAPABILITY EMPTY": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "deliveryServiceID":
GetDeliveryServiceId(t, "ds1")(),
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "ds1")()),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
"NOT FOUND when NON-EXISTENT REQUIRED
CAPABILITY": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "deliveryServiceID":
GetDeliveryServiceId(t, "ds1")(),
- "requiredCapability": "bogus",
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "ds1")()),
+ RequiredCapability:
util.StrPtr("bogus"),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
},
"NOT FOUND when NON-EXISTENT DELIVERY SERVICE
ID": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "deliveryServiceID": -1,
- "requiredCapability": "foo",
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(-1),
+ RequiredCapability:
util.StrPtr("foo"),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
},
"BAD REQUEST when INVALID DELIVERY SERVICE
TYPE": {
- ClientSession: TOSession, RequestBody:
map[string]interface{}{
- "deliveryServiceID":
GetDeliveryServiceId(t, "anymap-ds")(),
- "requiredCapability": "foo",
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "anymap-ds")()),
+ RequiredCapability:
util.StrPtr("foo"),
},
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
},
},
"DELETE": {
"OK when VALID request": {
- EndpointId: GetDeliveryServiceId(t,
"ds-top-req-cap"), ClientSession: TOSession,
- RequestBody:
map[string]interface{}{"requiredCapability": "ram"},
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "ds-top-req-cap")()),
+ RequiredCapability:
util.StrPtr("ram"),
+ },
Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
},
"NOT FOUND when NON-EXISTENT DELIVERYSERVICEID
parameter": {
- EndpointId: func() int { return -1 },
ClientSession: TOSession,
- RequestBody:
map[string]interface{}{"requiredCapability": "foo"},
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(-1),
+ RequiredCapability:
util.StrPtr("foo"),
+ },
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
},
"NOT FOUND when NON-EXISTENT REQUIREDCAPABILITY
parameter": {
- EndpointId: GetDeliveryServiceId(t,
"ds1"), ClientSession: TOSession,
- RequestBody:
map[string]interface{}{"requiredCapability": "bogus"},
+ ClientSession: TOSession,
+ RequestBody:
tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID:
util.IntPtr(GetDeliveryServiceId(t, "ds1")()),
+ RequiredCapability:
util.StrPtr("bogus"),
+ },
Expectations:
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusNotFound)),
},
},
- "GET AFTER CHANGES": {
- "OK when CHANGES made": {
- ClientSession: TOSession, RequestOpts:
client.RequestOptions{Header: http.Header{rfc.IfModifiedSince:
{currentTimeRFC}}},
- Expectations:
utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
- },
- },
}
for method, testCases := range methodTests {
t.Run(method, func(t *testing.T) {
for name, testCase := range testCases {
- dsrc :=
tc.DeliveryServicesRequiredCapability{}
-
- if val, ok :=
testCase.RequestOpts.QueryParameters["deliveryServiceId"]; ok {
- if _, err :=
strconv.Atoi(val[0]); err != nil {
-
testCase.RequestOpts.QueryParameters.Set("deliveryServiceId",
strconv.Itoa(GetDeliveryServiceId(t, val[0])()))
- }
- }
Review Comment:
Why take this part out?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]