You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2018/10/04 14:39:41 UTC

[trafficcontrol] 09/10: Fix TO Go feds to prevent assigning 0 dses

This is an automated email from the ASF dual-hosted git repository.

rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 84257c800c0979fba753d0c465ef32f690d70302
Author: Robert Butts <ro...@apache.org>
AuthorDate: Mon Oct 1 21:16:43 2018 -0600

    Fix TO Go feds to prevent assigning 0 dses
    
    Emulates Perl behavior.
---
 .../testing/api/{v13 => v14}/federations_test.go    | 21 +--------------------
 traffic_ops/traffic_ops_golang/federations/ds.go    |  4 ++++
 2 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/traffic_ops/testing/api/v13/federations_test.go b/traffic_ops/testing/api/v14/federations_test.go
similarity index 82%
rename from traffic_ops/testing/api/v13/federations_test.go
rename to traffic_ops/testing/api/v14/federations_test.go
index 1473f27..02cd4ee 100644
--- a/traffic_ops/testing/api/v13/federations_test.go
+++ b/traffic_ops/testing/api/v14/federations_test.go
@@ -1,4 +1,4 @@
-package v13
+package v14
 
 /*
 
@@ -33,12 +33,9 @@ func TestFederations(t *testing.T) {
 	CreateTestDeliveryServices(t)
 	CreateTestUsersDeliveryServices(t)
 	CreateTestCDNFederations(t)
-	// UpdateTestCDNFederations(t)
-	// GetTestCDNFederations(t)
 
 	PostTestFederationsDeliveryServices(t)
 	GetTestFederations(t)
-	DeleteTestFederationsDeliveryServices(t)
 
 	DeleteTestCDNFederations(t)
 	DeleteTestUsersDeliveryServices(t)
@@ -127,19 +124,3 @@ func PostTestFederationsDeliveryServices(t *testing.T) {
 	}
 	log.Debugln("PostTestFederationsDeliveryServices PASSED")
 }
-
-func DeleteTestFederationsDeliveryServices(t *testing.T) {
-	log.Debugln("DeleteTestFederationsDeliveryServices")
-	// doesn't actually call a DELETE method; this exists primarily to clean up PostTestFederationsDeliveryServices
-
-	if len(fedIDs) == 0 {
-		t.Fatalf("no federations, must have at least 1 federation to test federations deliveryservices\n")
-	}
-	fedID := fedIDs[0]
-
-	_, err := TOSession.CreateFederationDeliveryServices(fedID, nil, true)
-	if err != nil {
-		t.Fatalf("creating (deleting) federations delivery services: %v\n", err)
-	}
-	log.Debugln("DeleteTestFederationsDeliveryServices PASSED")
-}
diff --git a/traffic_ops/traffic_ops_golang/federations/ds.go b/traffic_ops/traffic_ops_golang/federations/ds.go
index 7ab0628..ba4742f 100644
--- a/traffic_ops/traffic_ops_golang/federations/ds.go
+++ b/traffic_ops/traffic_ops_golang/federations/ds.go
@@ -48,6 +48,10 @@ func PostDSes(w http.ResponseWriter, r *http.Request) {
 	}
 
 	if post.Replace != nil && *post.Replace {
+		if len(post.DSIDs) < 1 {
+			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("A federation must have at least one delivery service assigned"), nil)
+			return
+		}
 		if err := deleteDSFeds(inf.Tx.Tx, fedID); err != nil {
 			userErr, sysErr, errCode := api.ParseDBError(err)
 			api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)