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/06/03 19:52:18 UTC

[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5879: Add TO Client API for CDN Automation

ocket8888 commented on a change in pull request #5879:
URL: https://github.com/apache/trafficcontrol/pull/5879#discussion_r645082763



##########
File path: traffic_ops/testing/api/v4/cdns_test.go
##########
@@ -376,3 +441,166 @@ func DeleteTestCDNs(t *testing.T) {
 		}
 	}
 }
+
+func DeleteTestCDNsInvalidId(t *testing.T) {
+
+	delResp, reqInf, err := TOSession.DeleteCDN(100000, client.RequestOptions{})
+	if err == nil {
+		t.Errorf("Expected, no cdn with that key found  but got - alerts: %+v", delResp.Alerts)
+	}
+	if reqInf.StatusCode != http.StatusBadRequest {
+		t.Errorf("Expected 400 status code, got %v", reqInf.StatusCode)
+	}
+}
+
+func CreateTestCDNEmptyName(t *testing.T) {
+	if len(testData.CDNs) < 1 {
+		t.Fatalf("need at least one CDN to test creating CDNs")
+	}
+
+	firstData := testData.CDNs[0]
+	firstData.Name = ""
+	resp, reqInf, err := TOSession.CreateCDN(firstData, client.RequestOptions{})
+	if err == nil {
+		t.Errorf("Expected 'name' cannot be blank  but got - alerts: %+v", resp.Alerts)
+	}
+	if reqInf.StatusCode != http.StatusBadRequest {
+		t.Errorf("Expected 400 status code, got %v", reqInf.StatusCode)
+	}
+}
+
+func CreateTestCDNEmptyDomainName(t *testing.T) {
+	if len(testData.CDNs) < 1 {
+		t.Fatalf("need at least one CDN to test creating CDNs")
+	}
+
+	firstData := testData.CDNs[0]
+	firstData.DomainName = ""
+	resp, reqInf, err := TOSession.CreateCDN(firstData, client.RequestOptions{})
+	if err == nil {
+		t.Errorf("Expected 'domainName' cannot be blank  but got - alerts: %+v", resp.Alerts)
+	}
+	if reqInf.StatusCode != http.StatusBadRequest {
+		t.Errorf("Expected 400 status code, got %v", reqInf.StatusCode)
+	}
+}

Review comment:
       I don't think these tests are comprehensive enough to test what they claim to test; CDN names and domain names must be unique, so if there was a bug in the API that let you create a CDN with a blank name or a blank domain name, it would still give you back a non-nil error and a 400 status code. Because the CDN defined by `testData.CDNs[0]` was already created prior to this test - as long as creation is working properly - a CDN with the same domain name and name will exist when you attempt to create it in the first test and the second test, respectively.




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