You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2018/06/26 18:55:04 UTC

[trafficcontrol] 13/15: complete tenant test

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

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

commit e043ae3b18e35dca7c6198135d3714162b7e212f
Author: Dan Kirkwood <da...@apache.org>
AuthorDate: Fri Jun 22 13:45:34 2018 -0600

    complete tenant test
---
 traffic_ops/testing/api/v13/tenants_test.go | 43 +++++++++++++++++++----------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/traffic_ops/testing/api/v13/tenants_test.go b/traffic_ops/testing/api/v13/tenants_test.go
index dc08086..99bbbf2 100644
--- a/traffic_ops/testing/api/v13/tenants_test.go
+++ b/traffic_ops/testing/api/v13/tenants_test.go
@@ -17,6 +17,7 @@ package v13
 
 import (
 	"strconv"
+	"strings"
 	"testing"
 )
 
@@ -108,22 +109,34 @@ func UpdateTestTenants(t *testing.T) {
 
 func DeleteTestTenants(t *testing.T) {
 
-	for _, ten := range testData.Tenants {
-		// Retrieve the Tenant by name so we can get the id for the Update
-		respTenant, _, err := TOSession.TenantByName(ten.Name)
-		if err != nil {
-			t.Errorf("cannot GET Tenant by name: %v - %v\n", ten.Name, err)
-		}
+	t1 := "tenant1"
+	tenant1, _, err := TOSession.TenantByName(t1)
 
-		delResp, err := TOSession.DeleteTenant(strconv.Itoa(respTenant.ID))
-		if err != nil {
-			t.Errorf("cannot DELETE Tenant: %v - %v\n", err, delResp)
-		}
+	if err != nil {
+		t.Errorf("cannot GET Tenant by name: %v - %v\n", t1, err)
+	}
 
-		// Retrieve the Tenant to see if it got deleted
-		_, _, err = TOSession.TenantByName(ten.Name)
-		if err != nil {
-			t.Errorf("tenant not deleted: %v\n", err)
-		}
+	_, err = TOSession.DeleteTenant(strconv.Itoa(tenant1.ID))
+	if err == nil {
+		t.Errorf("%s has child tenants -- should not be able to delete", t1)
 	}
+	expected := "Tenant 'tenant1' has child tenants"
+	if !strings.Contains(err.Error(), expected) {
+		t.Errorf("expected error: %s;  got %s", expected, err.Error())
+	}
+
+	t2 := "tenant2"
+	tenant2, _, err := TOSession.TenantByName(t2)
+	_, err = TOSession.DeleteTenant(strconv.Itoa(tenant2.ID))
+	if err != nil {
+		t.Errorf("error deleting tenant %s: %v", t2, err)
+	}
+
+	// Now should be able to delete t1
+	tenant1, _, err = TOSession.TenantByName(t1)
+	_, err = TOSession.DeleteTenant(strconv.Itoa(tenant1.ID))
+	if err != nil {
+		t.Errorf("error deleting tenant %s: %v", t1, err)
+	}
+
 }