ocket8888 commented on code in PR #7733:
URL: https://github.com/apache/trafficcontrol/pull/7733#discussion_r1308130343


##########
traffic_ops/testing/api/v5/origins_test.go:
##########
@@ -162,113 +162,113 @@ func TestOrigins(t *testing.T) {
                        "POST": {
                                "BAD REQUEST when ALREADY EXISTS": {
                                        ClientSession: TOSession,
-                                       RequestBody: tc.Origin{
-                                               Name:            
util.Ptr("origin1"),
+                                       RequestBody: tc.OriginV5{
+                                               Name:            
*util.Ptr("origin1"),
                                                Cachegroup:      
util.Ptr("originCachegroup"),
                                                Coordinate:      
util.Ptr("coordinate1"),
-                                               DeliveryService: 
util.Ptr("ds1"),
-                                               FQDN:            
util.Ptr("origin1.example.com"),
+                                               DeliveryService: 
*util.Ptr("ds1"),
+                                               FQDN:            
*util.Ptr("origin1.example.com"),
                                                IPAddress:       
util.Ptr("1.2.3.4"),
                                                IP6Address:      
util.Ptr("dead:beef:cafe::42"),
                                                Port:            util.Ptr(1234),
                                                Profile:         
util.Ptr("ATS_EDGE_TIER_CACHE"),
-                                               Protocol:        
util.Ptr("http"),
-                                               TenantID:        
util.Ptr(GetTenantID(t, "tenant1")()),
-                                               IsPrimary:       util.Ptr(true),
+                                               Protocol:        
*util.Ptr("http"),
+                                               TenantID:        
*util.Ptr(GetTenantID(t, "tenant1")()),
+                                               IsPrimary:       
*util.Ptr(true),
                                        },
                                        Expectations: 
utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
                                },
                                "FORBIDDEN when CHILD TENANT CREATES ORIGIN 
OUTSIDE TENANCY": {
                                        ClientSession: tenant4UserSession,
-                                       RequestBody: tc.Origin{
-                                               Name:              
util.Ptr("originTenancyTest"),
+                                       RequestBody: tc.OriginV5{
+                                               Name:              
*util.Ptr("originTenancyTest"),
                                                Cachegroup:        
util.Ptr("originCachegroup"),
-                                               DeliveryServiceID: 
util.Ptr(GetDeliveryServiceId(t, "ds1")()),
-                                               FQDN:              
util.Ptr("origintenancy.example.com"),
-                                               Protocol:          
util.Ptr("http"),
-                                               TenantID:          
util.Ptr(GetTenantID(t, "tenant3")()),
+                                               DeliveryServiceID: 
*util.Ptr(GetDeliveryServiceId(t, "ds1")()),
+                                               FQDN:              
*util.Ptr("origintenancy.example.com"),
+                                               Protocol:          
*util.Ptr("http"),
+                                               TenantID:          
*util.Ptr(GetTenantID(t, "tenant3")()),

Review Comment:
   dereferecing and `util.Ptr` are inverse operations. Doing them both is 
redundant; just get rid of `util.Ptr`
   



##########
traffic_ops/traffic_ops_golang/origin/origins.go:
##########
@@ -487,3 +488,338 @@ func deleteQuery() string {
 WHERE id=:id`
        return query
 }
+
+// Get is the handler for GET requests to Origins of APIv5.
+func Get(w http.ResponseWriter, r *http.Request) {
+
+       var useIMS bool
+
+       inf, sysErr, userErr, errCode := api.NewInfo(r, nil, nil)
+       if sysErr != nil || userErr != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+               return
+       }
+       defer inf.Close()
+
+       origins, userErr, sysErr, errCode, _ := getOrigins(w.Header(), 
inf.Params, inf.Tx, inf.User, useIMS)
+       var returnable []tc.OriginV5

Review Comment:
   If zero origins match the filtering parameters sent by the client, this will 
cause it to return a `null` `response` property, when the proper representation 
for an empty list is the empty array, i.e. '[]'.
   
   > You don't need to do anything here if there are no origins, the response 
will be an empty array by default
   
   This is not correct. [The default - or "zero" - value of any slice is `nil` 
because slices are reference values](https://go.dev/play/p/bFHr2D1Upic).



##########
traffic_ops/v5-client/origin.go:
##########
@@ -85,24 +85,24 @@ func (to *Session) originIDs(origin *tc.Origin) error {
                origin.CoordinateID = coordinates.Response[0].ID
        }
 
-       if origin.TenantID == nil && origin.Tenant != nil {
-               opts.QueryParameters.Set("name", *origin.Tenant)
+       if &origin.TenantID == nil && &origin.Tenant != nil {

Review Comment:
   same as above



##########
traffic_ops/v5-client/origin.go:
##########
@@ -48,17 +48,17 @@ func (to *Session) originIDs(origin *tc.Origin) error {
                origin.CachegroupID = p.Response[0].ID
        }
 
-       if origin.DeliveryServiceID == nil && origin.DeliveryService != nil {
-               opts.QueryParameters.Set("xmlId", *origin.DeliveryService)
+       if &origin.DeliveryServiceID == nil && &origin.DeliveryService != nil {

Review Comment:
   `&v` for any variable `v` will never be `nil`, so this condition will never 
pass.



##########
traffic_ops/testing/api/v5/origins_test.go:
##########
@@ -630,12 +630,14 @@ func GetOriginID(t *testing.T, name string) func() int {
                assert.RequireNoError(t, err, "Get Origins Request failed with 
error:", err)
                assert.RequireEqual(t, 1, len(origins.Response), "Expected 
response object length 1, but got %d", len(origins.Response))
                assert.RequireNotNil(t, origins.Response[0].ID, "Expected ID to 
not be nil.")
-               return *origins.Response[0].ID
+               return origins.Response[0].ID
        }
 }
 
 func CreateTestOrigins(t *testing.T) {
        for _, origin := range testData.Origins {
+               origin.TenantID = GetTenantID(t, "root")()
+               origin.DeliveryServiceID = GetDeliveryServiceId(t, 
origin.DeliveryService)()

Review Comment:
   Do you know why you had to add this? It's because the changes you made to 
the `originIDs` function in the client aren't working, because you're looking 
for `nil` where it's impossible for `nil` to occur.



-- 
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]

Reply via email to