rob05c commented on a change in pull request #3163: Fix Traffic Ops Tenancy and 
Activity Bugs, Fix TO API Test Framework to work with Tenancy
URL: https://github.com/apache/trafficcontrol/pull/3163#discussion_r244461170
 
 

 ##########
 File path: traffic_ops/client/deliveryserviceserver.go
 ##########
 @@ -42,3 +45,48 @@ func (to *Session) CreateDeliveryServiceServers(dsID int, 
serverIDs []int, repla
        }
        return &resp.Response, nil
 }
+
+func (to *Session) DeleteDeliveryServiceServer(dsID int, serverID int) 
(tc.Alerts, ReqInf, error) {
+       route := apiBase + `/deliveryservice_server/` + strconv.Itoa(dsID) + 
"/" + strconv.Itoa(serverID)
+       reqResp, remoteAddr, err := to.request(http.MethodDelete, route, nil)
+       reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: 
remoteAddr}
+       if err != nil {
+               return tc.Alerts{}, reqInf, errors.New("requesting from Traffic 
Ops: " + err.Error())
+       }
+       defer reqResp.Body.Close()
+       resp := tc.Alerts{}
+       if err = json.NewDecoder(reqResp.Body).Decode(&resp); err != nil {
+               return tc.Alerts{}, reqInf, errors.New("decoding response: " + 
err.Error())
+       }
+       return resp, reqInf, nil
+}
+
+func (to *Session) GetDeliveryServiceServers() 
(tc.DeliveryServiceServerResponse, ReqInf, error) {
+       route := apiBase + `/deliveryserviceserver`
+       reqResp, remoteAddr, err := to.request(http.MethodGet, route, nil)
+       reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: 
remoteAddr}
+       if err != nil {
+               return tc.DeliveryServiceServerResponse{}, reqInf, 
errors.New("requesting from Traffic Ops: " + err.Error())
+       }
+       defer reqResp.Body.Close()
+       resp := tc.DeliveryServiceServerResponse{}
+       if err = json.NewDecoder(reqResp.Body).Decode(&resp); err != nil {
+               return tc.DeliveryServiceServerResponse{}, reqInf, 
errors.New("decoding response: " + err.Error())
+       }
+       return resp, reqInf, nil
+}
+
+func (to *Session) GetDeliveryServiceServersN(n int) 
(tc.DeliveryServiceServerResponse, ReqInf, error) {
+       route := apiBase + `/deliveryserviceserver` + `?limit=` + 
strconv.Itoa(n)
+       reqResp, remoteAddr, err := to.request(http.MethodGet, route, nil)
+       reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: 
remoteAddr}
+       if err != nil {
+               return tc.DeliveryServiceServerResponse{}, reqInf, 
errors.New("requesting from Traffic Ops: " + err.Error())
+       }
+       defer reqResp.Body.Close()
+       resp := tc.DeliveryServiceServerResponse{}
+       if err = json.NewDecoder(reqResp.Body).Decode(&resp); err != nil {
+               return tc.DeliveryServiceServerResponse{}, reqInf, 
errors.New("decoding response: " + err.Error())
+       }
+       return resp, reqInf, nil
 
 Review comment:
   Ok, I changed them to use a common func. IMO the abstraction isn't worth the 
readability cost. So, I changed it in the safest way I could think of.
   
   A sigil (-1 or 0) would be confusing, since not passing a limit results in 
the default API limit of 20, not infinite (which is the bug adding a `N` func 
fixes); likewise passing the API limit would be bug-prone if the API changed; 
so, passing the query param itself seemed the safest and least confusing.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to