rawlinp commented on a change in pull request #2545: Update TO Go 
cdns/:name/federations (CRUDer)
URL: https://github.com/apache/trafficcontrol/pull/2545#discussion_r206534562
 
 

 ##########
 File path: traffic_ops/testing/api/v13/cdnfederations_test.go
 ##########
 @@ -0,0 +1,131 @@
+package v13
+
+/*
+
+   Licensed 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.
+*/
+
+import (
+       "encoding/json"
+       "testing"
+
+       "github.com/apache/trafficcontrol/lib/go-log"
+)
+
+var fedIDs []int
+
+func TestCDNFederations(t *testing.T) {
+       CreateTestCDNs(t)
+       CreateTestTypes(t)
+       CreateTestDeliveryServices(t)
+       CreateTestCDNFederations(t)
+       UpdateTestCDNFederations(t)
+       GetTestCDNFederations(t)
+       DeleteTestCDNFederations(t)
+       DeleteTestDeliveryServices(t)
+       DeleteTestTypes(t)
+       DeleteTestCDNs(t)
+}
+
+func CreateTestCDNFederations(t *testing.T) {
+
+       //Every federation is associated with a cdn
+       for i, f := range testData.Federations {
+
+               //CDNs test data and Federations test data are not naturally 
parallel
+               if i >= len(testData.CDNs) {
+                       break
+               }
+
+               data, _, err := TOSession.CreateCDNFederationByName(f, 
testData.CDNs[i].Name)
+               if err != nil {
+                       t.Errorf("could not POST federations: " + err.Error())
+               }
+               bytes, _ := json.Marshal(data)
+               log.Debugf("POST Response: %s\n", bytes)
+
+               //need to save the ids, otherwise the other tests won't be able 
to reference the federations
+               if data.Response.ID == nil {
+                       t.Errorf("Federation id is nil after posting\n")
+               } else {
+                       fedIDs = append(fedIDs, *data.Response.ID)
+               }
+       }
+}
+
+func UpdateTestCDNFederations(t *testing.T) {
+
+       for _, id := range fedIDs {
+               fed, _, err := TOSession.GetCDNFederationsByID("foo", id)
+               if err != nil {
+                       t.Errorf("cannot GET federation by id: %v", err)
+               }
+
+               expectedCName := "new.cname."
+               fed.Response[0].CName = &expectedCName
+               resp, _, err := 
TOSession.UpdateCDNFederationsByID(fed.Response[0], "foo", id)
+               if err != nil {
+                       t.Errorf("cannot PUT federation by id: %v", err)
+               }
+               bytes, _ := json.Marshal(resp)
+               log.Debugf("PUT Response: %s\n", bytes)
+
+               resp2, _, err := TOSession.GetCDNFederationsByID("foo", id)
+               if err != nil {
+                       t.Errorf("cannot GET federation by id after PUT: %v", 
err)
+               }
+               bytes, _ = json.Marshal(resp2)
+               log.Debugf("GET Response: %s\n", bytes)
+
+               if resp2.Response[0].CName == nil {
+                       log.Errorf("CName is nil after updating\n")
+               } else if *resp2.Response[0].CName != expectedCName {
+                       t.Errorf("results do not match actual: %s, expected: 
%s\n", *resp2.Response[0].CName, expectedCName)
+               }
+
+       }
+}
+
+func GetTestCDNFederations(t *testing.T) {
+
+       //TOSession.GetCDNFederationsByName can't be tested until
 
 Review comment:
   bit of a nitpick, but comments are easier to read when there's a space after 
the `//`

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


With regards,
Apache Git Services

Reply via email to