You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/04/06 08:57:36 UTC

[GitHub] [trafficcontrol] dmohan001c opened a new pull request #5717: Dsautomation

dmohan001c opened a new pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717


   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - [ ] This PR fixes #REPLACE_ME OR is not related to any Issue <!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - CDN in a Box
   - Documentation
   - Grove
   - Traffic Control Client <!-- Please specify which; e.g. 'Python', 'Go', 'Java' -->
   - Traffic Monitor
   - Traffic Ops
   - Traffic Ops ORT
   - Traffic Portal
   - Traffic Router
   - Traffic Stats
   - Traffic Vault
   - CI tests
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   <!-- If this PR fixes a bug, please list here all of the affected versions - to
   the best of your knowledge. It's also pretty helpful to include a commit hash
   of where 'master' is at the time this PR is opened (if it affects master),
   because what 'master' means will change over time. For example, if this PR
   fixes a bug that's present in master (at commit hash '1df853c8'), in v4.0.0,
   and in the current 4.0.1 Release candidate (e.g. RC1), then this list would
   look like:
   
   - master (1df853c8)
   - 4.0.0
   - 4.0.1 (RC1)
   
   If you don't know what other versions might have this bug, AND don't know how
   to find the commit hash of 'master', then feel free to leave this section
   blank (or, preferably, delete it entirely).
    -->
   
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [ ] This PR includes tests OR I have explained why tests are unnecessary
   - [ ] This PR includes documentation OR I have explained why documentation is unnecessary
   - [ ] This PR includes an update to CHANGELOG.md OR such an update is not necessary
   - [ ] This PR includes any and all required license headers
   - [ ] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
   -->
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r608034593



##########
File path: .gitignore
##########
@@ -79,3 +79,6 @@ __debug_bin
 ./traffic_ops_golang
 # Created by TP/TO docker integration tests
 junit/
+go.mod
+go.sum
+vendor/modules.txt

Review comment:
       We should not do this. It makes the project no longer a Go module.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610509199



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)

Review comment:
       Handled Null values.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610509604



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)

Review comment:
       Fixed nil values.

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidXmlId(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr("test", nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting Delivery service by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Xml Id shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func SortTestDeliveryServices(t *testing.T) {
+	var header http.Header
+	var sortedList []string
+	resp, _, err := TOSession.GetDeliveryServicesV4(header, nil)
+	if err != nil {
+		t.Fatalf("Expected no error, but got %v", err.Error())
+	}
+	for i, _ := range resp {
+		sortedList = append(sortedList, *resp[i].XMLID)

Review comment:
       Fixed nil values

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidXmlId(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr("test", nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting Delivery service by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Xml Id shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func SortTestDeliveryServices(t *testing.T) {
+	var header http.Header
+	var sortedList []string
+	resp, _, err := TOSession.GetDeliveryServicesV4(header, nil)
+	if err != nil {
+		t.Fatalf("Expected no error, but got %v", err.Error())

Review comment:
       Removed .Error




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c closed pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
dmohan001c closed pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-814722873


   Re-opening pull requests to run checks.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c closed pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
dmohan001c closed pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610508610



##########
File path: .gitignore
##########
@@ -78,4 +78,4 @@ __debug_bin
 # built local binaries
 ./traffic_ops_golang
 # Created by TP/TO docker integration tests
-junit/
+junit/

Review comment:
       Added new line.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610509080



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))

Review comment:
       Handled Null values.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r608747671



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)

Review comment:
       If `firstDS.CDNID` *and* `firstDS.CDNName` are both `nil`, this will segfault

##########
File path: .gitignore
##########
@@ -78,4 +78,4 @@ __debug_bin
 # built local binaries
 ./traffic_ops_golang
 # Created by TP/TO docker integration tests
-junit/
+junit/

Review comment:
       missing newline at eof

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)

Review comment:
       If `resp[0].Type` is `nil`, this will segfault

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidXmlId(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr("test", nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting Delivery service by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Xml Id shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func SortTestDeliveryServices(t *testing.T) {
+	var header http.Header
+	var sortedList []string
+	resp, _, err := TOSession.GetDeliveryServicesV4(header, nil)
+	if err != nil {
+		t.Fatalf("Expected no error, but got %v", err.Error())

Review comment:
       nit but `.Error` is unnecessary when using the `%v` formatting parameter

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)

Review comment:
       This will segfault if `resp[0].Tenant` is `nil`

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {

Review comment:
       if `resp[0].ProfileName` is `nil`, this will segfault

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)

Review comment:
       If `resp[0].LogsEnabled` *or* `firstDS.LogsEnabled` is/are `nil`, this will segfault

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)

Review comment:
       if `resp[0].XMLID` is `nil`, this will segfault

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)

Review comment:
       if `firstDS.XMLID` is `nil`, this will segfault

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))

Review comment:
       if `firstDS.LogsEnabled` is `nil`, this will segfault

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidXmlId(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr("test", nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting Delivery service by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Xml Id shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func SortTestDeliveryServices(t *testing.T) {
+	var header http.Header
+	var sortedList []string
+	resp, _, err := TOSession.GetDeliveryServicesV4(header, nil)
+	if err != nil {
+		t.Fatalf("Expected no error, but got %v", err.Error())
+	}
+	for i, _ := range resp {
+		sortedList = append(sortedList, *resp[i].XMLID)
+	}
+
+	res := sort.SliceIsSorted(sortedList, func(p, q int) bool {
+		return sortedList[p] < sortedList[q]
+	})
+	if res != true {
+		t.Errorf("list is not sorted by their XML Id: %v", sortedList)
+	}
+}
+
+func SortTestDeliveryServicesDesc(t *testing.T) {
+
+	var header http.Header
+	respAsc, _, err1 := TOSession.GetDeliveryServicesV4(header, nil)
+	params := url.Values{}
+	params.Set("sortOrder", "desc")
+	respDesc, _, err2 := TOSession.GetDeliveryServicesV4(header, params)
+
+	if err1 != nil {
+		t.Fatalf("Expected no error, but got error in DS Ascending %v", err1.Error())
+	}
+	if err2 != nil {
+		t.Fatalf("Expected no error, but got error in DS Descending %v", err2.Error())
+	}
+	// reverse the descending-sorted response and compare it to the ascending-sorted one
+	for start, end := 0, len(respDesc)-1; start < end; start, end = start+1, end-1 {
+		respDesc[start], respDesc[end] = respDesc[end], respDesc[start]
+	}
+	if !reflect.DeepEqual(respDesc[0].XMLID, respAsc[0].XMLID) {

Review comment:
       if `respDesc` *or* `respAsc` have zero length or are `nil`, or if `respDesc[0].XMLID` *or* `respAsc[0].XMLID` is/are `nil`, this will segfault

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidXmlId(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr("test", nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting Delivery service by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Xml Id shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func SortTestDeliveryServices(t *testing.T) {
+	var header http.Header
+	var sortedList []string
+	resp, _, err := TOSession.GetDeliveryServicesV4(header, nil)
+	if err != nil {
+		t.Fatalf("Expected no error, but got %v", err.Error())
+	}
+	for i, _ := range resp {
+		sortedList = append(sortedList, *resp[i].XMLID)

Review comment:
       if `resp[i].XMLID` is `nil`, this will segfault




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r609210182



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)

Review comment:
       can you give him an example of how stuff should be written to avoid that?

##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)

Review comment:
       can you give him an example of how stuff should be written to avoid segfaults?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-816815035


   > Re-opening pull requests to run checks.
   
   rather than closing/repoening the PR, you can click on the details of the failed check and hit this button to re-run it:
   
   ![image](https://user-images.githubusercontent.com/251272/114214332-6ad13c80-9921-11eb-946b-2a84cc6c35a8.png)
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-815434186


   Re-opening pull request to test checks


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-816707138


   The server code is working fine in my local. But it's failing here while executing the integration tests. So, I am going to rebase the code in my local and test it again.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610508987



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)

Review comment:
       updated the code as per your suggestion and fixed the segfault.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-814288329


   > Created automation script for GET - Delivery services
   Looking at the code, it seems the primary purpose of this PR is to add testing surrounding the Go client's interactions with Traffic Ops's `/deliveryservices` API endpoint - is that fair to say?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610509299



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {

Review comment:
       Handled null values.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-814220213


   > What does this Pull Request do?
   
   Created automation script for GET - Delivery services.
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-814683660


   Re-opening pull request for re-run


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c closed pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c closed pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c closed pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c closed pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 edited a comment on pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
ocket8888 edited a comment on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-814288329


   > Created automation script for GET - Delivery services
   
   Looking at the code, it seems the primary purpose of this PR is to add testing surrounding the Go client's interactions with Traffic Ops's `/deliveryservices` API endpoint - is that fair to say?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r609890309



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)

Review comment:
       all of the tests added already guard against a few segfaults with stuff like `if len(testData.DeliveryServices) > 0` and `if firstDS.CDNID == nil && firstDS.CDNName != nil` so I figured he was good on it. That's not really the issue here. There's just an edge case, because above it checks if the CDNID is `nil` to avoid a segfault by just fetching the CDN ID from its name, but it doesn't handle the case where the name is also `nil`. If it were me, I'd just write this like:
   ```go
   func GetDeliveryServiceByCdn(t *testing.T) {
   	if len(testData.DeliveryServices) < 1 {
   		t.Fatal("Need at least one Delivery Service to test getting Delivery Services by CDN")
   	}
   	firstDS := testData.DeliveryServices[0]
   
   	if firstDS.CDNID == nil {
   		if firstDS.CDNName == nil {
   			t.Fatal("Cannot get CDN ID for test Delivery Service: CDN Name was null or undefined")
   		}
   		// Get CDNID from the CDN Name and assign a reference to it to firstDS.CDNID
   	}
   	// Continue with the test}
   ```
   
   but basically there're two ways to check for `nil` values/array length to avoid segmentation faults. You can do it the way you're already doing it where you only do things if it's not `nil`, so like
   
   ```go
   func TestSomething(t *testing.T) {
   	value := funcThatPossiblyReturnsNil()
   	if value != nil {
   		// the rest of the test
   	}
   }
   ```
   
   but personally I don't like that approach because it can cause some pretty deep nesting. Instead, I like to consider not having the right data to test a test failure itself, so I'd write that test like:
   
   ```go
   func TestSomething(t *testing.T) {
   	value := funcThatPossiblyReturnsNil()
   	if value == nil {
   		t.Fatal("testing value was nil")
   	}
   	// the rest of the test
   }
   ```
   
   ```go




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610509446



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)

Review comment:
       Handled Nil values




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#issuecomment-814215649


   What does this Pull Request do?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Dsautomation

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r608349506



##########
File path: .gitignore
##########
@@ -79,3 +79,6 @@ __debug_bin
 ./traffic_ops_golang
 # Created by TP/TO docker integration tests
 junit/
+go.mod
+go.sum
+vendor/modules.txt

Review comment:
       Fixed




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r609890309



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)

Review comment:
       all of the tests added already guard against a few segfaults with stuff like `if len(testData.DeliveryServices) > 0` and `if firstDS.CDNID == nil && firstDS.CDNName != nil` so I figured he was good on it. That's not really the issue here. There's just an edge case, because above it checks if the CDNID is `nil` to avoid a segfault by just fetching the CDN ID from its name, but it doesn't handle the case where the name is also `nil`. If it were me, I'd just write this like:
   ```go
   func GetDeliveryServiceByCdn(t *testing.T) {
   	if len(testData.DeliveryServices) < 1 {
   		t.Fatal("Need at least one Delivery Service to test getting Delivery Services by CDN")
   	}
   	firstDS := testData.DeliveryServices[0]
   
   	if firstDS.CDNID == nil {
   		if firstDS.CDNName == nil {
   			t.Fatal("Cannot get CDN ID for test Delivery Service: CDN Name was null or undefined")
   		}
   		// Get CDNID from the CDN Name and assign a reference to it to firstDS.CDNID
   	}
   	// Continue with the test
   }
   ```
   
   but basically there're two ways to check for `nil` values/array length to avoid segmentation faults. You can do it the way you're already doing it where you only do things if it's not `nil`, so like
   
   ```go
   func TestSomething(t *testing.T) {
   	value := funcThatPossiblyReturnsNil()
   	if value != nil {
   		// the rest of the test
   	}
   }
   ```
   
   but personally I don't like that approach because it can cause some pretty deep nesting. Instead, I like to consider not having the right data to test a test failure itself, so I'd write that test like:
   
   ```go
   func TestSomething(t *testing.T) {
   	value := funcThatPossiblyReturnsNil()
   	if value == nil {
   		t.Fatal("testing value was nil")
   	}
   	// the rest of the test
   }
   ```
   
   ```go




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] dmohan001c commented on a change in pull request #5717: Adds TO client api tests for GET /deliveryservices

Posted by GitBox <gi...@apache.org>.
dmohan001c commented on a change in pull request #5717:
URL: https://github.com/apache/trafficcontrol/pull/5717#discussion_r610509919



##########
File path: traffic_ops/testing/api/v4/deliveryservices_test.go
##########
@@ -1238,6 +1254,272 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNID == nil && firstDS.CDNName != nil {
+			cdns, _, err := TOSession.GetCDNByNameWithHdr(*firstDS.CDNName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting CDN by Name: %v", err)
+			}
+			if len(cdns) == 0 {
+				t.Fatalf("no CDN named %v" + *firstDS.CDNName)
+			}
+			firstDS.CDNID = &cdns[0].ID
+		}
+		resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(*firstDS.CDNID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+		} else {
+			if *resp[0].CDNName != *firstDS.CDNName {
+				t.Fatalf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNIDWithHdr(10000, nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		qparams := url.Values{}
+		qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+		resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+		if err != nil {
+			t.Fatalf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+		} else {
+			if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+				t.Fatalf("name expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileID == nil && firstDS.ProfileName != nil {
+			profile, _, err := TOSession.GetProfileByNameWithHdr(*firstDS.ProfileName, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Profile by Name: %v", err)
+			}
+			if len(profile) == 0 {
+				t.Fatalf("no Profile named %v" + *firstDS.ProfileName)
+			}
+			firstDS.ProfileID = &profile[0].ID
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if *resp[0].ProfileName != *firstDS.ProfileName {
+					t.Fatalf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TenantID == nil && firstDS.Tenant != nil {
+			tenant, _, err := TOSession.TenantByNameWithHdr(*firstDS.Tenant, nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Tenant by Name: %v", err)
+			}
+			if tenant == nil {
+				t.Fatalf("no Tenant named %v" + *firstDS.Tenant)
+			}
+			firstDS.TenantID = &tenant.ID
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Tenant != *firstDS.Tenant {
+					t.Fatalf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.TypeID == nil && firstDS.Type != nil {
+			ty, _, err := TOSession.GetTypeByNameWithHdr(firstDS.Type.String(), nil)
+			if err != nil {
+				t.Fatalf("Error in Getting Type by Name: %v", err)
+			}
+			if len(ty) == 0 {
+				t.Fatalf("no Type named %v" + firstDS.Type.String())
+			}
+			firstDS.TypeID = &ty[0].ID
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+			if err != nil {
+				t.Fatalf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if *resp[0].Type != *firstDS.Type {
+					t.Fatalf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServicesV4(nil, qparams)
+	if err != nil {
+		t.Fatalf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr(*firstDS.XMLID, nil)
+		if err != nil {
+			t.Fatalf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+		}
+		if len(resp) == 0 {
+			t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+		} else {
+			if *resp[0].XMLID != *firstDS.XMLID {
+				t.Fatalf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidXmlId(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServiceByXMLIDNullableWithHdr("test", nil)
+	if err != nil {
+		t.Fatalf("Error!! Getting Delivery service by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Fatalf("Error!! Invalid Xml Id shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func SortTestDeliveryServices(t *testing.T) {
+	var header http.Header
+	var sortedList []string
+	resp, _, err := TOSession.GetDeliveryServicesV4(header, nil)
+	if err != nil {
+		t.Fatalf("Expected no error, but got %v", err.Error())
+	}
+	for i, _ := range resp {
+		sortedList = append(sortedList, *resp[i].XMLID)
+	}
+
+	res := sort.SliceIsSorted(sortedList, func(p, q int) bool {
+		return sortedList[p] < sortedList[q]
+	})
+	if res != true {
+		t.Errorf("list is not sorted by their XML Id: %v", sortedList)
+	}
+}
+
+func SortTestDeliveryServicesDesc(t *testing.T) {
+
+	var header http.Header
+	respAsc, _, err1 := TOSession.GetDeliveryServicesV4(header, nil)
+	params := url.Values{}
+	params.Set("sortOrder", "desc")
+	respDesc, _, err2 := TOSession.GetDeliveryServicesV4(header, params)
+
+	if err1 != nil {
+		t.Fatalf("Expected no error, but got error in DS Ascending %v", err1.Error())
+	}
+	if err2 != nil {
+		t.Fatalf("Expected no error, but got error in DS Descending %v", err2.Error())
+	}
+	// reverse the descending-sorted response and compare it to the ascending-sorted one
+	for start, end := 0, len(respDesc)-1; start < end; start, end = start+1, end-1 {
+		respDesc[start], respDesc[end] = respDesc[end], respDesc[start]
+	}
+	if !reflect.DeepEqual(respDesc[0].XMLID, respAsc[0].XMLID) {

Review comment:
       Handled nil values.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org