ocket8888 commented on a change in pull request #5328:
URL: https://github.com/apache/trafficcontrol/pull/5328#discussion_r536396240
##########
File path: traffic_ops/testing/api/v3/deliveryserviceservers_test.go
##########
@@ -17,21 +17,339 @@ package v3
import (
"errors"
+ "fmt"
"net/http"
"net/url"
"strconv"
"strings"
"testing"
+ "time"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
)
+func TryToRemoveLastServerInDeliveryService(t *testing.T) {
+ cdns, _, err := TOSession.GetCDNsWithHdr(nil)
+ if err != nil {
+ t.Fatalf("Could not fetch CDNs: %v", err)
+ }
+ if len(cdns) < 1 {
+ t.Fatal("Need at least one CDN to test removing the last server
from a Delivery Service")
+ }
+
+ cdnID := cdns[0].ID
+
+ user, _, err := TOSession.GetUserCurrentWithHdr(nil)
+ if err != nil {
+ t.Fatalf("Could not fetch current user: %v", err)
+ }
+ if user == nil {
+ t.Fatalf("Current user is null")
+ }
+ if user.TenantID == nil {
+ t.Fatalf("Current user has null Tenant ID")
+ }
+
+ types, _, err := TOSession.GetTypesWithHdr(nil, "deliveryservice")
+ if err != nil {
+ t.Fatalf("Could not fetch Types: %v", err)
+ }
+ if len(types) < 1 {
+ t.Fatal("Need at least one Type with 'useInTable' of
'deliveryservice' to create a Delivery Service")
+ }
+ dsTypeID := types[0].ID
+
+ xmlid := fmt.Sprintf("test-%d", time.Now().Unix())
+ ds := tc.DeliveryServiceNullableV30{
+ DeliveryServiceNullableV15: tc.DeliveryServiceNullableV15{
+ DeliveryServiceNullableV14:
tc.DeliveryServiceNullableV14{
+ DeliveryServiceNullableV13:
tc.DeliveryServiceNullableV13{
+ DeliveryServiceNullableV12:
tc.DeliveryServiceNullableV12{
+ DeliveryServiceNullableV11:
tc.DeliveryServiceNullableV11{
+ Active:
new(bool),
+
AnonymousBlockingEnabled: new(bool),
+ CDNID:
&cdnID,
+ DisplayName:
util.StrPtr("test"),
+ DSCP:
new(int),
+ GeoLimit:
new(int),
+ GeoProvider:
new(int),
+ InitialDispersion:
new(int),
+ IPV6RoutingEnabled:
new(bool),
+ LogsEnabled:
new(bool),
+ MissLat:
new(float64),
+ MissLong:
new(float64),
+ OrgServerFQDN:
util.StrPtr("https://example.com"),
+ Protocol:
new(int),
+ QStringIgnore:
new(int),
+ RangeRequestHandling:
new(int),
+ RegionalGeoBlocking:
new(bool),
+ Signed:
false,
+ TenantID:
user.TenantID,
+ TypeID:
&dsTypeID,
+ XMLID:
&xmlid,
+ },
+ },
+ },
+ },
+ },
+ }
+ *ds.InitialDispersion = 1
+ *ds.Active = true
+ ds, _, err = TOSession.CreateDeliveryServiceV30(ds)
+ if err != nil {
+ t.Fatalf("Failed to create Delivery Service: %v", err)
+ }
+ if ds.ID == nil {
+ t.Fatal("Delivery Service had null/undefined ID after creation")
+ }
+
+ cacheGroups, _, err := TOSession.GetCacheGroupsNullableWithHdr(nil)
+ if err != nil {
+ t.Fatalf("Could not fetch Cache Groups: %v", err)
+ }
+ if len(cacheGroups) < 1 {
+ t.Fatal("Need at least one Cache Group for testing")
+ }
+ if cacheGroups[0].ID == nil {
+ t.Fatal("Got a Cache Group for testing with null or undefined
ID")
+ }
+ cacheGroupID := *cacheGroups[0].ID
+
+ profile := tc.Profile{
+ CDNID: cdnID,
+ Description: "test",
+ Name: xmlid,
+ Type: "ATS_PROFILE",
+ }
+ alerts, _, err := TOSession.CreateProfile(profile)
+ t.Logf("Alerts from creating Profile: %s",
strings.Join(alerts.ToStrings(), ", "))
+ if err != nil {
+ t.Fatalf("Failed to create new Profile in CDN #%d: %v", cdnID,
err)
+ }
+ profiles, _, err := TOSession.GetProfileByNameWithHdr(profile.Name, nil)
+ if err != nil {
+ t.Fatalf("Could not fetch Profile '%s' after creation: %v",
profile.Name, err)
+ }
+ if len(profiles) != 1 {
+ t.Fatalf("Expected exactly one Profile named '%s'; got: %d",
profile.Name, len(profiles))
+ }
+ profile = profiles[0]
+
+ physLocs, _, err := TOSession.GetPhysLocationsWithHdr(nil, nil)
+ if err != nil {
+ t.Fatalf("Could not fetch Physical Locations: %v", err)
+ }
+ if len(physLocs) < 1 {
+ t.Fatal("Need at least one Physical Location")
+ }
+ physLoc := physLocs[0]
+
+ statuses, _, err := TOSession.GetStatusesWithHdr(nil)
+ if err != nil {
+ t.Fatalf("Could not fetch Statuses: %v", err)
+ }
+ if len(statuses) < 1 {
+ t.Fatal("Need at least one Status")
+ }
+
+ var statusID int
+ var badStatusID int
+ found := false
+ foundBad := false
+ for _, status := range statuses {
+ if status.Name == "ONLINE" || status.Name == "REPORTED" {
+ statusID = status.ID
+ found = true
+ if foundBad {
+ break
+ }
+ } else {
+ badStatusID = status.ID
+ foundBad = true
+ if found {
+ break
+ }
+ }
+ }
+ if !found || !foundBad {
+ t.Fatal("Need at least one status with the name 'ONLINE' or
'REPORTED' and at least one status with neither of those names")
+ }
+
+ types, _, err = TOSession.GetTypesWithHdr(nil, "server")
+ if err != nil {
+ t.Fatalf("Could not fetch Types: %v", err)
+ }
+ if len(types) < 1 {
+ t.Fatal("Need at least one Type with 'useInTable' of 'server'
to create a server")
+ }
+ serverTypeID := types[0].ID
+
+ server := tc.ServerV30{
Review comment:
No longer relevant
##########
File path: traffic_ops/testing/api/v3/deliveryserviceservers_test.go
##########
@@ -17,21 +17,339 @@ package v3
import (
"errors"
+ "fmt"
"net/http"
"net/url"
"strconv"
"strings"
"testing"
+ "time"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
)
+func TryToRemoveLastServerInDeliveryService(t *testing.T) {
+ cdns, _, err := TOSession.GetCDNsWithHdr(nil)
+ if err != nil {
+ t.Fatalf("Could not fetch CDNs: %v", err)
+ }
+ if len(cdns) < 1 {
+ t.Fatal("Need at least one CDN to test removing the last server
from a Delivery Service")
+ }
+
+ cdnID := cdns[0].ID
+
+ user, _, err := TOSession.GetUserCurrentWithHdr(nil)
+ if err != nil {
+ t.Fatalf("Could not fetch current user: %v", err)
+ }
+ if user == nil {
+ t.Fatalf("Current user is null")
+ }
+ if user.TenantID == nil {
+ t.Fatalf("Current user has null Tenant ID")
+ }
+
+ types, _, err := TOSession.GetTypesWithHdr(nil, "deliveryservice")
+ if err != nil {
+ t.Fatalf("Could not fetch Types: %v", err)
+ }
+ if len(types) < 1 {
+ t.Fatal("Need at least one Type with 'useInTable' of
'deliveryservice' to create a Delivery Service")
+ }
+ dsTypeID := types[0].ID
+
+ xmlid := fmt.Sprintf("test-%d", time.Now().Unix())
+ ds := tc.DeliveryServiceNullableV30{
Review comment:
No longer relevant
----------------------------------------------------------------
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:
[email protected]