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/05/03 20:37:15 UTC

[trafficcontrol] branch master updated: Adds TO client api tests for DS automation (#5736)

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 4175a92  Adds TO client api tests for DS automation (#5736)
4175a92 is described below

commit 4175a92212f06ce994e7ca7c87fa5652c8d78fd7
Author: dmohan001c <de...@comcast.com>
AuthorDate: Tue May 4 02:06:58 2021 +0530

    Adds TO client api tests for DS automation (#5736)
    
    * added test case for CacheGroup Pagination functionalites
    
    * added tests for get delivery services by cdn
    
    * Formatted the code using gofmt
    
    * removed codes to check for errors
    
    * formatted the code using go fmt
    
    * added invalid scenarios for ds get
    
    * added tests for profile and logs enabled
    
    * formatted using go fmt
    
    * added tests for get ds by tenant,type,xml id and sort functionality
    
    * removed xml, type, tenant tests
    
    * removed sort desc function
    
    * removed sort desc function
    
    * removed sort functionality
    
    * removed unused import
    
    * formatted using go fmt
    
    * Added tests for ds by logs enabled
    
    * formatted the code using go fmt
    
    * added tests for get ds by profile
    
    * added profile name in pre-requisite
    
    * added tests for ds tenant,xmlid, type
    
    * adding logs to check errors
    
    * added git diff
    
    * Added newline at the EOF
---
 .github/actions/to-integration-tests/entrypoint.sh |  19 +-
 .../testing/api/v4/deliveryservices_test.go        | 337 ++++++++++++++++++++-
 traffic_ops/testing/api/v4/tc-fixtures.json        |   2 +-
 3 files changed, 349 insertions(+), 9 deletions(-)

diff --git a/.github/actions/to-integration-tests/entrypoint.sh b/.github/actions/to-integration-tests/entrypoint.sh
index 1638c21..4479d33 100755
--- a/.github/actions/to-integration-tests/entrypoint.sh
+++ b/.github/actions/to-integration-tests/entrypoint.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
++set -e
++
 download_go() {
 	. build/functions.sh
 	if verify_and_set_go_version; then
@@ -179,13 +181,16 @@ envsubst <"${resources}/riak.json" >riak.conf
 truncate --size=0 warning.log error.log # Removes output from previous API versions and makes sure files exist
 ./traffic_ops_golang --cfg ./cdn.conf --dbcfg ./database.conf -riakcfg riak.conf &
 
-# TODO - Make these logs build artifacts
-# 2>&1 makes terminal output go faster, even though stderr will not contain anything
-tail -f warning.log 2>&1 | color_and_prefix "${yellow_bg}" 'Traffic Ops' &
-tail -f error.log 2>&1 | color_and_prefix "${red_bg}" 'Traffic Ops' &
-
-
 cd "../testing/api/v$INPUT_VERSION"
 
 cp "${resources}/traffic-ops-test.json" traffic-ops-test.conf
-go test -test.v --cfg traffic-ops-test.conf
+go test -test.v --cfg traffic-ops-test.conf || code="$?" && code="$?"
+
+# TODO - Make these logs build artifacts
+# 2>&1 makes terminal output go faster, even though stderr will not contain anything
+echo "------------ TRAFFIC OPS LOGS ------------"
+cd -
+color_and_prefix "${yellow_bg}" 'Traffic Ops' <warning.log 2>&1
+color_and_prefix "${red_bg}" 'Traffic Ops' <error.log 2>&1
+
+exit "$code"
diff --git a/traffic_ops/testing/api/v4/deliveryservices_test.go b/traffic_ops/testing/api/v4/deliveryservices_test.go
index 498ea9d..80ced6f 100644
--- a/traffic_ops/testing/api/v4/deliveryservices_test.go
+++ b/traffic_ops/testing/api/v4/deliveryservices_test.go
@@ -21,6 +21,7 @@ import (
 	"net/http"
 	"net/url"
 	"reflect"
+	"sort"
 	"strconv"
 	"strings"
 	"testing"
@@ -45,6 +46,7 @@ func TestDeliveryServices(t *testing.T) {
 			SSLDeliveryServiceCDNUpdateTest(t)
 			GetTestDeliveryServicesURLSigKeys(t)
 		}
+
 		GetTestDeliveryServicesIMS(t)
 		GetAccessibleToTest(t)
 		UpdateTestDeliveryServices(t)
@@ -67,6 +69,20 @@ func TestDeliveryServices(t *testing.T) {
 		header.Set(rfc.IfMatch, etag)
 		UpdateTestDeliveryServicesWithHeaders(t, header)
 		VerifyPaginationSupportDS(t)
+		GetDeliveryServiceByCdn(t)
+		GetDeliveryServiceByInvalidCdn(t)
+		GetDeliveryServiceByInvalidProfile(t)
+		GetDeliveryServiceByInvalidTenant(t)
+		GetDeliveryServiceByInvalidType(t)
+		GetDeliveryServiceByInvalidAccessibleTo(t)
+		GetDeliveryServiceByInvalidXmlId(t)
+		GetDeliveryServiceByLogsEnabled(t)
+		GetDeliveryServiceByValidProfile(t)
+		GetDeliveryServiceByValidTenant(t)
+		GetDeliveryServiceByValidType(t)
+		GetDeliveryServiceByValidXmlId(t)
+		SortTestDeliveryServicesDesc(t)
+		SortTestDeliveryServices(t)
 	})
 }
 
@@ -1205,7 +1221,7 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	qparams.Set("page", "2")
 	deliveryserviceWithPage, _, err := TOSession.GetDeliveryServices(nil, qparams)
 	if !reflect.DeepEqual(deliveryservice[1:2], deliveryserviceWithPage) {
-		t.Error("expected GET cachegroup with limit = 1, page = 2 to return second result")
+		t.Error("expected GET deliveryservice with limit = 1, page = 2 to return second result")
 	}
 
 	qparams = url.Values{}
@@ -1238,6 +1254,111 @@ func VerifyPaginationSupportDS(t *testing.T) {
 	}
 }
 
+func GetDeliveryServiceByCdn(t *testing.T) {
+
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.CDNName != nil {
+			if firstDS.CDNID == nil {
+				cdns, _, err := TOSession.GetCDNByName(*firstDS.CDNName, nil)
+				if err != nil {
+					t.Errorf("Error in Getting CDN by Name: %v", err)
+				}
+				if len(cdns) == 0 {
+					t.Errorf("no CDN named %v" + *firstDS.CDNName)
+				}
+				firstDS.CDNID = &cdns[0].ID
+			}
+			resp, _, err := TOSession.GetDeliveryServicesByCDNID(*firstDS.CDNID, nil)
+			if err != nil {
+				t.Errorf("Error in Getting DeliveryServices by CDN ID: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the CDN %v", *firstDS.CDNName)
+			} else {
+				if resp[0].CDNName == nil {
+					t.Errorf("CDN Name is not available in response")
+				} else {
+					if *resp[0].CDNName != *firstDS.CDNName {
+						t.Errorf("CDN Name expected: %s, actual: %s", *firstDS.CDNName, *resp[0].CDNName)
+					}
+				}
+			}
+		} else {
+			t.Errorf("CDN Name is nil in the pre-requisites")
+		}
+	}
+}
+
+func GetDeliveryServiceByInvalidCdn(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServicesByCDNID(10000, nil)
+	if err != nil {
+		t.Errorf("Error!! Getting CDN by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Errorf("Error!! Invalid CDN shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidProfile(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("profile", "10000")
+	resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+	if err != nil {
+		t.Errorf("Error!! Getting deliveryservice by Invalid Profile ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Errorf("Error!! Invalid Profile shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidTenant(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("tenant", "10000")
+	resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+	if err != nil {
+		t.Errorf("Error!! Getting Deliveryservice by Invalid Tenant ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Errorf("Error!! Invalid Tenant shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidType(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("type", "10000")
+	resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+	if err != nil {
+		t.Errorf("Error!! Getting Deliveryservice by Invalid Type ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Errorf("Error!! Invalid Type shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidAccessibleTo(t *testing.T) {
+	qparams := url.Values{}
+	qparams.Set("accessibleTo", "10000")
+	resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+	if err != nil {
+		t.Errorf("Error!! Getting Deliveryservice by Invalid AccessibleTo %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Errorf("Error!! Invalid AccessibleTo shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
+func GetDeliveryServiceByInvalidXmlId(t *testing.T) {
+	resp, _, err := TOSession.GetDeliveryServiceByXMLID("test", nil)
+	if err != nil {
+		t.Errorf("Error!! Getting Delivery service by Invalid ID %v", err)
+	}
+	if len(resp) >= 1 {
+		t.Errorf("Error!! Invalid Xml Id shouldn't have any response %v Error %v", resp, err)
+	}
+}
+
 func GetTestDeliveryServicesURLSigKeys(t *testing.T) {
 	if len(testData.DeliveryServices) == 0 {
 		t.Fatal("couldn't get the xml ID of test DS")
@@ -1252,3 +1373,217 @@ func GetTestDeliveryServicesURLSigKeys(t *testing.T) {
 		t.Error("failed to get url sig keys: " + err.Error())
 	}
 }
+
+func GetDeliveryServiceByLogsEnabled(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.LogsEnabled != nil {
+			qparams := url.Values{}
+			qparams.Set("logsEnabled", strconv.FormatBool(*firstDS.LogsEnabled))
+			resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+			if err != nil {
+				t.Errorf("Error in Getting deliveryservice by logsEnabled: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Logs Enabled %v", *firstDS.LogsEnabled)
+			} else {
+				if resp[0].LogsEnabled == nil {
+					t.Errorf("Logs Enabled is not available in response")
+				} else {
+					if *resp[0].LogsEnabled != *firstDS.LogsEnabled {
+						t.Errorf("Logs enabled status expected: %t, actual: %t", *firstDS.LogsEnabled, *resp[0].LogsEnabled)
+					}
+				}
+			}
+		} else {
+			t.Errorf("Logs Enabled is nil in the pre-requisites ")
+		}
+	}
+}
+
+func GetDeliveryServiceByValidProfile(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.ProfileName == nil {
+			t.Errorf("Profile name is nil in the Pre-requisites")
+		} else {
+			if firstDS.ProfileID == nil {
+				profile, _, err := TOSession.GetProfileByName(*firstDS.ProfileName, nil)
+				if err != nil {
+					t.Errorf("Error in Getting Profile by Name: %v", err)
+				}
+				if len(profile) == 0 {
+					t.Errorf("no Profile named %v" + *firstDS.ProfileName)
+				}
+				firstDS.ProfileID = &profile[0].ID
+			}
+			qparams := url.Values{}
+			qparams.Set("profile", strconv.Itoa(*firstDS.ProfileID))
+			resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+			if err != nil {
+				t.Errorf("Error in Getting deliveryservice by Profile: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Profile %v", *firstDS.ProfileName)
+			} else {
+				if resp[0].ProfileName == nil {
+					t.Errorf("Profile Name is not available in response")
+				} else {
+					if *resp[0].ProfileName != *firstDS.ProfileName {
+						t.Errorf("Profile name expected: %s, actual: %s", *firstDS.ProfileName, *resp[0].ProfileName)
+					}
+				}
+			}
+		}
+	}
+}
+
+func GetDeliveryServiceByValidTenant(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.Tenant != nil {
+			if firstDS.TenantID == nil {
+				tenant, _, err := TOSession.GetTenantByName(*firstDS.Tenant, nil)
+				if err != nil {
+					t.Errorf("Error in Getting Tenant by Name: %v", err)
+				}
+				firstDS.TenantID = &tenant.ID
+			}
+			qparams := url.Values{}
+			qparams.Set("tenant", strconv.Itoa(*firstDS.TenantID))
+			resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+			if err != nil {
+				t.Errorf("Error in Getting Deliveryservice by Tenant:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Tenant %v", *firstDS.CDNName)
+			} else {
+				if resp[0].Tenant == nil {
+					t.Errorf("Tenant Name is not available in response")
+				} else {
+					if *resp[0].Tenant != *firstDS.Tenant {
+						t.Errorf("name expected: %s, actual: %s", *firstDS.Tenant, *resp[0].Tenant)
+					}
+				}
+			}
+		} else {
+			t.Errorf("Tenant name is nil in the Pre-requisites")
+		}
+	}
+}
+
+func GetDeliveryServiceByValidType(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.Type != nil {
+			if firstDS.TypeID == nil {
+				ty, _, err := TOSession.GetTypeByName(firstDS.Type.String(), nil)
+				if err != nil {
+					t.Errorf("Error in Getting Type by Name: %v", err)
+				}
+				if len(ty) == 0 {
+					t.Errorf("no Type named %v" + firstDS.Type.String())
+				}
+				firstDS.TypeID = &ty[0].ID
+			}
+			qparams := url.Values{}
+			qparams.Set("type", strconv.Itoa(*firstDS.TypeID))
+			resp, _, err := TOSession.GetDeliveryServices(nil, qparams)
+			if err != nil {
+				t.Errorf("Error in Getting Deliveryservice by Type:%v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the Type %v", *firstDS.CDNName)
+			} else {
+				if resp[0].Type == nil {
+					t.Errorf("Type is not available in response")
+				} else {
+					if *resp[0].Type != *firstDS.Type {
+						t.Errorf("Type expected: %s, actual: %s", *firstDS.Type, *resp[0].Type)
+					}
+				}
+			}
+		} else {
+			t.Errorf("Type name is nil in the Pre-requisites")
+		}
+	}
+}
+
+func GetDeliveryServiceByValidXmlId(t *testing.T) {
+	if len(testData.DeliveryServices) > 0 {
+		firstDS := testData.DeliveryServices[0]
+
+		if firstDS.XMLID != nil {
+			resp, _, err := TOSession.GetDeliveryServiceByXMLID(*firstDS.XMLID, nil)
+			if err != nil {
+				t.Errorf("Error in Getting DeliveryServices by XML ID: %v - %v", err, resp)
+			}
+			if len(resp) == 0 {
+				t.Errorf("No delivery service available for the XML ID %v", *firstDS.XMLID)
+			} else {
+				if resp[0].XMLID == nil {
+					t.Errorf("XML ID is not available in response")
+				} else {
+					if *resp[0].XMLID != *firstDS.XMLID {
+						t.Errorf("Delivery Service Name expected: %s, actual: %s", *firstDS.XMLID, *resp[0].XMLID)
+					}
+				}
+			}
+		} else {
+			t.Errorf("XML ID is nil in the Pre-requisites")
+		}
+	}
+}
+
+func SortTestDeliveryServicesDesc(t *testing.T) {
+
+	var header http.Header
+	respAsc, _, err1 := TOSession.GetDeliveryServices(header, nil)
+	params := url.Values{}
+	params.Set("sortOrder", "desc")
+	respDesc, _, err2 := TOSession.GetDeliveryServices(header, params)
+
+	if err1 != nil {
+		t.Errorf("Expected no error, but got error in DS Ascending %v", err1)
+	}
+	if err2 != nil {
+		t.Errorf("Expected no error, but got error in DS Descending %v", err2)
+	}
+
+	if len(respAsc) > 0 && len(respDesc) > 0 {
+		// reverse the descending-sorted response and compare it to the ascending-sorted one
+		for start, end := 0, len(respDesc)-1; start < end; start, end = start+1, end-1 {
+			respDesc[start], respDesc[end] = respDesc[end], respDesc[start]
+		}
+		if respDesc[0].XMLID != nil && respAsc[0].XMLID != nil {
+			if !reflect.DeepEqual(respDesc[0].XMLID, respAsc[0].XMLID) {
+				t.Errorf("Role responses are not equal after reversal: %v - %v", *respDesc[0].XMLID, *respAsc[0].XMLID)
+			}
+		}
+	} else {
+		t.Errorf("No Response returned from GET Delivery Service using SortOrder")
+	}
+}
+
+func SortTestDeliveryServices(t *testing.T) {
+	var header http.Header
+	var sortedList []string
+	resp, _, err := TOSession.GetDeliveryServices(header, nil)
+	if err != nil {
+		t.Errorf("Expected no error, but got %v", err)
+	}
+	for i, _ := range resp {
+		sortedList = append(sortedList, *resp[i].XMLID)
+	}
+
+	res := sort.SliceIsSorted(sortedList, func(p, q int) bool {
+		return sortedList[p] < sortedList[q]
+	})
+	if res != true {
+		t.Errorf("list is not sorted by their XML Id: %v", sortedList)
+	}
+}
diff --git a/traffic_ops/testing/api/v4/tc-fixtures.json b/traffic_ops/testing/api/v4/tc-fixtures.json
index dc3ca8b..6cbc85d 100644
--- a/traffic_ops/testing/api/v4/tc-fixtures.json
+++ b/traffic_ops/testing/api/v4/tc-fixtures.json
@@ -462,7 +462,7 @@
             "orgServerFqdn": "http://origin.example.net",
             "originShield": null,
             "profileDescription": null,
-            "profileName": null,
+            "profileName": "ATS_EDGE_TIER_CACHE",
             "protocol": 2,
             "qstringIgnore": 1,
             "rangeRequestHandling": 0,