You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2021/09/13 21:58:51 UTC

[trafficcontrol] branch master updated: Add TO Client API for ServerServerCapability Automation (#6151)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 999bf8f8 Add TO Client API for ServerServerCapability Automation (#6151)
999bf8f8 is described below

commit 999bf8f83d47c3b7185e166e774a63ab0ae2b445
Author: dmohan001c <de...@comcast.com>
AuthorDate: Tue Sep 14 03:28:41 2021 +0530

    Add TO Client API for ServerServerCapability Automation (#6151)
    
    * added test for pagination, delete serverserverCapability with invalid scenario
    
    * reverted the changes made in client method
    
    * uncommented the test code
    
    * added null check validation server id
---
 .../testing/api/v4/serverservercapability_test.go  | 105 ++++++++++++++++++++-
 1 file changed, 103 insertions(+), 2 deletions(-)

diff --git a/traffic_ops/testing/api/v4/serverservercapability_test.go b/traffic_ops/testing/api/v4/serverservercapability_test.go
index d1f08f8..fb6a2d7 100644
--- a/traffic_ops/testing/api/v4/serverservercapability_test.go
+++ b/traffic_ops/testing/api/v4/serverservercapability_test.go
@@ -18,6 +18,7 @@ package v4
 import (
 	"net/http"
 	"net/url"
+	"reflect"
 	"sort"
 	"strconv"
 	"testing"
@@ -36,6 +37,8 @@ func TestServerServerCapabilities(t *testing.T) {
 		GetTestServerServerCapabilities(t)
 		GetDeliveryServiceServersWithCapabilities(t)
 		UpdateTestServerServerCapabilities(t)
+		GetTestPaginationSupportSsc(t)
+		DeleteTestServerServerCapabilityWithInvalidData(t)
 	})
 }
 
@@ -421,7 +424,6 @@ func DeleteTestServerServerCapabilities(t *testing.T) {
 			t.Errorf("could not remove Capability '%s' from server '%s' (#%d): %v - alerts: %+v", *ssc.ServerCapability, *ssc.Server, *ssc.ServerID, err, alerts.Alerts)
 		}
 	}
-
 }
 
 func DeleteTestServerServerCapabilitiesForTopologiesValidation(t *testing.T) {
@@ -502,7 +504,6 @@ func DeleteTestServerServerCapabilitiesForTopologies(t *testing.T) {
 			t.Errorf("could not remove Capability '%s' from server '%s': %v - alerts: %+v", *ssc.ServerCapability, *ssc.Server, err, resp.Alerts)
 		}
 	}
-
 }
 
 func GetDeliveryServiceServersWithCapabilities(t *testing.T) {
@@ -596,3 +597,103 @@ func GetDeliveryServiceServersWithCapabilities(t *testing.T) {
 		t.Errorf("Unexpected error removing server #%d from Delivery Service #%d: %v - alerts: %+v", midID, *ds.ID, err, alerts.Alerts)
 	}
 }
+
+func GetTestPaginationSupportSsc(t *testing.T) {
+	opts := client.NewRequestOptions()
+	opts.QueryParameters.Set("orderby", "id")
+	resp, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities: %v - alerts: %+v", err, resp.Alerts)
+	}
+	ServerServerCapabilities := resp.Response
+	if len(ServerServerCapabilities) < 3 {
+		t.Fatalf("Need at least 3 server server capabilities in Traffic Ops to test pagination support, found: %d", len(ServerServerCapabilities))
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	serverServerCapWithLimit, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order and Limit: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[:1], serverServerCapWithLimit.Response) {
+		t.Error("expected GET Server Server Capabilities with limit = 1 to return first result")
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("offset", "1")
+	serverServerCapWithOffset, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order, Limit and Offset: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[1:2], serverServerCapWithOffset.Response) {
+		t.Error("expected GET server server capabilities with limit = 1, offset = 1 to return second result")
+	}
+
+	opts.QueryParameters.Set("orderby", "id")
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("page", "2")
+	serverServerCapWithPage, _, err := TOSession.GetServerServerCapabilities(opts)
+	if err != nil {
+		t.Fatalf("cannot get server server capabilities by Order, Limit and Page: %v - alerts: %+v", err, resp.Alerts)
+	}
+	if !reflect.DeepEqual(ServerServerCapabilities[1:2], serverServerCapWithPage.Response) {
+		t.Error("expected GET Server Server Capabilities with limit = 1, page = 2 to return second result")
+	}
+
+	opts.QueryParameters = url.Values{}
+	opts.QueryParameters.Set("limit", "-2")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when limit is not bigger than -1")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be bigger than -1") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for limit is not bigger than -1, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("offset", "0")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when offset is not a positive integer")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for offset is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+
+	opts.QueryParameters = url.Values{}
+	opts.QueryParameters.Set("limit", "1")
+	opts.QueryParameters.Set("page", "0")
+	resp, _, err = TOSession.GetServerServerCapabilities(opts)
+	if err == nil {
+		t.Error("expected GET Server Server Capabilities to return an error when page is not a positive integer")
+	} else if !alertsHaveError(resp.Alerts.Alerts, "must be a positive integer") {
+		t.Errorf("expected GET Server Server Capabilities to return an error for page is not a positive integer, actual error: %v - alerts: %+v", err, resp.Alerts)
+	}
+}
+
+func DeleteTestServerServerCapabilityWithInvalidData(t *testing.T) {
+	// Get Server server Capabilities to delete them
+	sscs, _, err := TOSession.GetServerServerCapabilities(client.RequestOptions{})
+	if err != nil {
+		t.Fatalf("cannot get server/Capability associations: %v - alerts: %+v", err, sscs.Alerts)
+	}
+	if len(sscs.Response) < 1 {
+		t.Fatalf("No Server Server Capability available to test invalid scenario")
+	}
+	ssc := sscs.Response[0]
+	if ssc.ServerID == nil {
+		t.Fatal("Cache Group selected for testing had a null or undefined name")
+	}
+
+	//Delete Server Server Capability with Invalid Server Capability
+	alerts, _, err := TOSession.DeleteServerServerCapability(*sscs.Response[0].ServerID, "abcd", client.RequestOptions{})
+	if err == nil {
+		t.Fatalf("Expected no server server_capability with that key found, actual: %v - alerts: %+v", err, alerts.Alerts)
+	}
+
+	//Missing Server Capability
+	alerts, _, err = TOSession.DeleteServerServerCapability(*sscs.Response[0].ServerID, "", client.RequestOptions{})
+	if err == nil {
+		t.Fatalf("Expected missing key: serverCapability, actual: %v - alerts: %+v", err, alerts.Alerts)
+	}
+}