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/02/26 21:54:16 UTC
[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #5582: Copying over tests and config changes from 5.1
mattjackson220 commented on a change in pull request #5582:
URL: https://github.com/apache/trafficcontrol/pull/5582#discussion_r583939115
##########
File path: traffic_ops/testing/api/v4/serverservercapability_test.go
##########
@@ -385,3 +387,91 @@ func DeleteTestServerServerCapabilitiesForTopologies(t *testing.T) {
}
}
+
+func GetDeliveryServiceServersWithCapabilities(t *testing.T) {
+ dses, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, url.Values{"xmlId": []string{"ds4"}})
+ if err != nil {
+ t.Fatalf("Failed to get Delivery Services: %v", err)
+ }
+ if len(dses) < 1 {
+ t.Fatal("Failed to get at least one Delivery Service")
+ }
+
+ ds := dses[0]
+ if ds.ID == nil {
+ t.Fatal("Got Delivery Service with nil ID")
+ }
+
+ // Get an edge
+ params := url.Values{}
+ params.Add("hostName", "atlanta-edge-16")
+ rs, _, err := TOSession.GetServersWithHdr(¶ms, nil)
+ if err != nil {
+ t.Fatalf("Failed to fetch server information: %v", err)
+ } else if len(rs.Response) == 0 {
+ t.Fatalf("Failed to fetch server information: No results returned!")
+ }
+ edgeID := *rs.Response[0].ID
+
+ // Get a MID
+ params = url.Values{}
+ params.Add("hostName", "atlanta-mid-02")
+ rs, _, err = TOSession.GetServersWithHdr(¶ms, nil)
+ if err != nil {
+ t.Fatalf("Failed to fetch server information: %v", err)
+ } else if len(rs.Response) == 0 {
+ t.Fatalf("Failed to fetch server information: No results returned!")
+ }
+ midID := *rs.Response[0].ID
+ // assign edge and mid
+ _, _, err = TOSession.CreateDeliveryServiceServers(*ds.ID, []int{edgeID, midID}, true)
+ if err != nil {
+ t.Fatalf("expected no error while assigning servers to DS, but got %s", err.Error())
+ }
+ params = url.Values{}
+ params.Add("dsId", strconv.Itoa(*ds.ID))
+ servers, _, err := TOSession.GetServersWithHdr(¶ms, nil)
+ if err != nil {
+ t.Fatalf("Failed to get server by Delivery Service ID: %v", err)
+ }
+ if len(servers.Response) != 2 {
+ t.Fatalf("expected to get 2 servers for Delivery Service: %d, actual: %d", *ds.ID, len(servers.Response))
+ }
+
+ // now assign a capability
+ reqCap := tc.DeliveryServicesRequiredCapability{
+ DeliveryServiceID: ds.ID,
+ RequiredCapability: util.StrPtr("blah"),
+ }
+ _, _, err = TOSession.CreateDeliveryServicesRequiredCapability(reqCap)
+ // this should fail because the mid doesn't have the reqd capability
+ if err == nil {
+ t.Fatalf("expected error creating DS reqd capability, but got nothing")
+ }
+ ssc := tc.ServerServerCapability{
+ ServerID: &midID,
+ ServerCapability: util.StrPtr("blah"),
+ }
+ // assign the capability to the mid
+ _, _, err = TOSession.CreateServerServerCapability(ssc)
+ if err != nil {
+ t.Fatalf("couldn't assign server capability to server with ID %d, err: %s", midID, err.Error())
+ }
+ _, _, err = TOSession.CreateDeliveryServicesRequiredCapability(reqCap)
+ // this should pass now because the mid has the reqd capability
+ if err != nil {
+ t.Fatalf("expected no error creating DS reqd capability, but got %s", err.Error())
+ }
+
+ params = url.Values{}
+ params.Add("dsId", strconv.Itoa(*ds.ID))
+ servers, _, err = TOSession.GetServersWithHdr(¶ms, nil)
+ if err != nil {
+ t.Fatalf("Failed to get server by Delivery Service ID: %v", err)
+ }
+ if len(servers.Response) != 2 {
+ t.Fatalf("expected to get 2 servers for Delivery Service: %d, actual: %d", *ds.ID, len(servers.Response))
+ }
+ _, _, err = TOSession.DeleteDeliveryServiceServer(*ds.ID, edgeID)
+ _, _, err = TOSession.DeleteDeliveryServiceServer(*ds.ID, midID)
Review comment:
can you add some `err` checks on these 2 to make sure we know if the deletes errored?
----------------------------------------------------------------
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