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 2022/06/01 19:12:12 UTC

[GitHub] [trafficcontrol] ocket8888 commented on a diff in pull request #6851: Refactor Servers Test

ocket8888 commented on code in PR #6851:
URL: https://github.com/apache/trafficcontrol/pull/6851#discussion_r887211158


##########
traffic_ops/testing/api/v3/servers_test.go:
##########
@@ -26,1017 +26,562 @@ import (
 
 	"github.com/apache/trafficcontrol/lib/go-rfc"
 	"github.com/apache/trafficcontrol/lib/go-tc"
-	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/testing/api/assert"
+	"github.com/apache/trafficcontrol/traffic_ops/testing/api/utils"
+	"github.com/apache/trafficcontrol/traffic_ops/toclientlib"
 )
 
 func TestServers(t *testing.T) {
-	WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, DeliveryServices}, func() {
-		GetTestServersIMS(t)
-		currentTime := time.Now().UTC().Add(-5 * time.Second)
-		time := currentTime.Format(time.RFC1123)
-		var header http.Header
-		header = make(map[string][]string)
-		header.Set(rfc.IfModifiedSince, time)
-		header.Set(rfc.IfUnmodifiedSince, time)
-		UpdateTestServers(t)
-		UpdateTestServersWithHeaders(t, header)
-		GetTestServersDetails(t)
-		GetTestServers(t)
-		GetTestServersIMSAfterChange(t, header)
-		GetTestServersQueryParameters(t)
-		header = make(map[string][]string)
-		etag := rfc.ETag(currentTime)
-		header.Set(rfc.IfMatch, etag)
-		UpdateTestServersWithHeaders(t, header)
-		CreateTestBlankFields(t)
-		CreateTestServerWithoutProfileId(t)
-		UniqueIPProfileTestServers(t)
-		UpdateTestServerStatus(t)
-		LastServerInTopologyCacheGroup(t)
-	})
-}
-
-func LastServerInTopologyCacheGroup(t *testing.T) {
-	const cacheGroupName = "topology-mid-cg-01"
-	const moveToCacheGroup = "topology-mid-cg-02"
-	const topologyName = "forked-topology"
-	const cdnName = "cdn2"
-	const expectedLength = 1
-	cdns, _, err := TOSession.GetCDNByNameWithHdr(cdnName, nil)
-	if err != nil {
-		t.Fatalf("unable to GET CDN: %v", err)
-	}
-	cdnID := cdns[0].ID
-	params := url.Values{}
-	params.Add("cachegroupName", cacheGroupName)
-	params.Add("topology", topologyName)
-	params.Add("cdn", strconv.Itoa(cdnID))
-	servers, _, err := TOSession.GetServersWithHdr(&params, nil)
-	if err != nil {
-		t.Fatalf("getting server from cdn %s from cachegroup %s in topology %s: %s", cdnName, cacheGroupName, topologyName, err.Error())
-	}
-	if len(servers.Response) != expectedLength {
-		t.Fatalf("expected to get %d server from cdn %s from cachegroup %s in topology %s, got %d servers", expectedLength, cdnName, cacheGroupName, topologyName, len(servers.Response))
-	}
-	server := servers.Response[0]
-	_, reqInf, err := TOSession.DeleteServerByID(*server.ID)
-	if err == nil {
-		t.Fatalf("expected an error deleting server with id %d, received no error", *server.ID)
-	}
-	if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
-		t.Fatalf("expected a 400-level error deleting server with id %d, got status code %d: %s", *server.ID, reqInf.StatusCode, err.Error())
-	}
-
-	// attempt to move it to another CDN while it's the last server in the cachegroup in its CDN
-	cdns, _, err = TOSession.GetCDNByNameWithHdr("cdn1", nil)
-	if err != nil {
-		t.Fatalf("unable to GET CDN: %v", err)
-	}
-	newCDNID := cdns[0].ID
-	oldCDNID := *server.CDNID
-	server.CDNID = &newCDNID
-	profiles, _, err := TOSession.GetProfileByNameWithHdr("MID1", nil)
-	if err != nil {
-		t.Fatalf("unable to GET profile: %v", err)
-	}
-	newProfile := profiles[0].ID
-	oldProfile := *server.ProfileID
-	server.ProfileID = &newProfile
-	_, _, err = TOSession.UpdateServerByIDWithHdr(*server.ID, server, nil)
-	if err == nil {
-		t.Fatalf("changing the CDN of the last server (%s) in a CDN in a cachegroup used by a topology assigned to a delivery service(s) in that CDN - expected: error, actual: nil", *server.HostName)
-	}
-	server.CDNID = &oldCDNID
-	server.ProfileID = &oldProfile
-
-	params = url.Values{}
-	params.Add("name", moveToCacheGroup)
-	cgs, _, err := TOSession.GetCacheGroupsByQueryParamsWithHdr(params, nil)
-	if err != nil {
-		t.Fatalf("getting cachegroup with hostname %s: %s", moveToCacheGroup, err.Error())
-	}
-	if len(cgs) != expectedLength {
-		t.Fatalf("expected %d cachegroup with hostname %s, received %d cachegroups", expectedLength, moveToCacheGroup, len(cgs))
-	}
-
-	_, _, err = TOSession.UpdateServerByIDWithHdr(*server.ID, server, nil)
-	if err != nil {
-		t.Fatalf("error updating server with hostname %s without moving it to a different cachegroup: %s", *server.HostName, err.Error())
-	}
-
-	*server.CachegroupID = *cgs[0].ID
-	_, _, err = TOSession.UpdateServerByIDWithHdr(*server.ID, server, nil)
-	if err == nil {
-		t.Fatalf("expected an error moving server with id %s to a different cachegroup, received no error", *server.HostName)
-	}
-	if reqInf.StatusCode < http.StatusBadRequest || reqInf.StatusCode >= http.StatusInternalServerError {
-		t.Fatalf("expected a 400-level error moving server with id %d to a different cachegroup, got status code %d: %s", *server.ID, reqInf.StatusCode, err.Error())
-	}
-}
-
-func UpdateTestServerStatus(t *testing.T) {
-	if len(testData.Servers) < 1 {
-		t.Fatal("Need at least one server to test updating")
-	}
-
-	firstServer := testData.Servers[0]
-	if firstServer.HostName == nil {
-		t.Fatalf("First test server had nil hostname: %+v", firstServer)
-	}
-
-	hostName := *firstServer.HostName
-	params := url.Values{}
-	params.Add("hostName", hostName)
-
-	// Retrieve the server by hostname so we can get the id for the Update
-	resp, _, err := TOSession.GetServersWithHdr(&params, nil)
-	if err != nil {
-		t.Fatalf("cannot GET Server by hostname '%s': %v - %v", hostName, err, resp.Alerts)
-	}
-	if len(resp.Response) < 1 {
-		t.Fatalf("Expected at least one server to exist by hostname '%s'", hostName)
-	}
-	if len(resp.Response) > 1 {
-		t.Errorf("Expected exactly one server to exist by hostname '%s' - actual: %d", hostName, len(resp.Response))
-		t.Logf("Testing will proceed with server: %+v", resp.Response[0])
-	}
-	remoteServer := resp.Response[0]
-	if remoteServer.ID == nil {
-		t.Fatalf("Got null ID for server '%s'", hostName)
-	}
-	id := fmt.Sprintf("%v", *resp.Response[0].ID)
-	idParam := url.Values{}
-	idParam.Add("id", id)
-	originalStatusID := 0
-	updatedStatusID := 0
-
-	statuses, _, err := TOSession.GetStatusesWithHdr(nil)
-	if err != nil {
-		t.Fatalf("cannot get statuses: %v", err.Error())
-	}
-	for _, status := range statuses {
-		if status.Name == "REPORTED" {
-			originalStatusID = status.ID
-		}
-		if status.Name == "ONLINE" {
-			updatedStatusID = status.ID
+	WithObjs(t, []TCObj{CDNs, Types, Tenants, Users, Parameters, Profiles, Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies, ServiceCategories, DeliveryServices, DeliveryServiceServerAssignments}, func() {
+
+		currentTime := time.Now().UTC().Add(-15 * time.Second)
+		currentTimeRFC := currentTime.Format(time.RFC1123)
+		tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)
+
+		methodTests := utils.V3TestCase{
+			"GET": {
+				"NOT MODIFIED when NO CHANGES made": {
+					ClientSession:  TOSession,
+					RequestHeaders: http.Header{rfc.IfModifiedSince: {tomorrow}},
+					Expectations:   utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusNotModified)),
+				},
+				"OK when VALID HOSTNAME parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"hostName": {"atlanta-edge-01"}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseHasLength(1),
+						validateServerFields(map[string]interface{}{"HostName": "atlanta-edge-01"})),
+				},
+				"OK when VALID CACHEGROUP parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"cachegroup": {strconv.Itoa(GetCacheGroupId(t, "cachegroup1")())}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateServerFields(map[string]interface{}{"CachegroupID": GetCacheGroupId(t, "cachegroup1")()})),
+				},
+				"OK when VALID CACHEGROUPNAME parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"cachegroupName": {"topology-mid-cg-01"}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateServerFields(map[string]interface{}{"Cachegroup": "topology-mid-cg-01"})),
+				},
+				"OK when VALID CDN parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"cdn": {strconv.Itoa(GetCDNId(t, "cdn2"))}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateServerFields(map[string]interface{}{"CDNID": GetCDNId(t, "cdn2")})),
+				},
+				"OK when VALID DSID parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"dsId": {strconv.Itoa(GetDeliveryServiceId(t, "test-ds-server-assignments")())}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateExpectedServers([]string{"test-ds-server-assignments"})),
+				},
+				"OK when VALID PARENTCACHEGROUP parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"parentCacheGroup": {strconv.Itoa(GetCacheGroupId(t, "parentCachegroup")())}},
+					Expectations:  utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1)),
+				},
+				"OK when VALID PROFILEID parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"profileId": {strconv.Itoa(GetProfileId(t, "EDGE1"))}},
+					Expectations:  utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1)),
+				},
+				"OK when VALID STATUS parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"status": {"REPORTED"}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateServerFields(map[string]interface{}{"Status": "REPORTED"})),
+				},
+				"OK when VALID TOPOLOGY parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"topology": {"mso-topology"}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateExpectedServers([]string{"denver-mso-org-01", "denver-mso-org-02", "edge1-cdn1-cg3", "edge2-cdn1-cg3",
+							"atlanta-mid-01", "atlanta-mid-16", "atlanta-mid-17", "edgeInCachegroup3", "midInParentCachegroup",
+							"midInSecondaryCachegroup", "midInSecondaryCachegroupInCDN1"})),
+				},
+				"OK when VALID TYPE parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"type": {"EDGE"}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateServerFields(map[string]interface{}{"Type": "EDGE"})),
+				},
+				"VALID SERVER LIST when using TOPOLOGY BASED DSID parameter": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"dsId": {strconv.Itoa(GetDeliveryServiceId(t, "ds-top")())}},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1),
+						validateExpectedServers([]string{"denver-mso-org-01"})),
+				},
+				"VALID SERVER TYPE when DS TOPOLOGY CONTAINS NO MIDS": {
+					ClientSession: TOSession,
+					RequestParams: url.Values{"dsId": {strconv.Itoa(GetDeliveryServiceId(t, "ds-based-top-with-no-mids")())}},
+					Expectations:  utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), utils.ResponseLengthGreaterOrEqual(1), validateServerTypeIsNotMid()),
+				},
+			},
+			"POST": {
+				"BAD REQUEST when BLANK PROFILEID": {
+					ClientSession: TOSession,
+					RequestBody:   generateServer(t, map[string]interface{}{"profileId": nil}),
+					Expectations:  utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+			},
+			"PUT": {
+				"OK when VALID request": {
+					EndpointId:    GetServerId(t, "atlanta-edge-03"),
+					ClientSession: TOSession,
+					RequestBody: map[string]interface{}{
+						"id":           GetServerId(t, "atlanta-edge-03")(),
+						"cdnId":        GetCDNId(t, "cdn1"),
+						"cachegroupId": GetCacheGroupId(t, "cachegroup1")(),
+						"domainName":   "updateddomainname",
+						"hostName":     "atl-edge-01",
+						"httpsPort":    8080,
+						"interfaces": []map[string]interface{}{{
+							"ipAddresses": []map[string]interface{}{
+								{
+									"address":        "2345:1234:12:2::4/64",
+									"gateway":        "2345:1234:12:2::4",
+									"serviceAddress": false,
+								},
+								{
+									"address":        "127.0.0.13/30",
+									"gateway":        "127.0.0.1",
+									"serviceAddress": true,
+								},
+							},
+							"monitor":        true,
+							"mtu":            uint64(1280),
+							"name":           "bond1",
+							"routerHostName": "router5",
+							"routerPort":     "9004",
+						}},
+						"physLocationId": GetPhysLocationId(t, "Denver")(),
+						"profileId":      GetProfileId(t, "EDGE1"),
+						"rack":           "RR 119.03",
+						"statusId":       GetStatusId(t, "REPORTED")(),
+						"tcpPort":        8080,
+						"typeId":         GetTypeId(t, "EDGE"),
+						"updPending":     true,
+					},
+					Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
+						validateServerFieldsForUpdate("atl-edge-01", map[string]interface{}{
+							"CDNName": "cdn1", "Cachegroup": "cachegroup1", "DomainName": "updateddomainname", "HostName": "atl-edge-01",
+							"HTTPSPort": 8080, "InterfaceName": "bond1", "MTU": uint64(1280), "PhysLocation": "Denver", "Rack": "RR 119.03",
+							"TCPPort": 8080, "TypeID": GetTypeId(t, "EDGE"),
+						})),
+				},
+				"BAD REQUEST when CHANGING XMPPID": {
+					EndpointId:    GetServerId(t, "atlanta-edge-16"),
+					ClientSession: TOSession,
+					RequestBody: generateServer(t, map[string]interface{}{
+						"id":     GetServerId(t, "atlanta-edge-16")(),
+						"xmppId": "CHANGINGTHIS",
+					}),
+					Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+				"CONFLICT when UPDATING SERVER TYPE when ASSIGNED to DS": {
+					EndpointId:    GetServerId(t, "test-ds-server-assignments"),
+					ClientSession: TOSession,
+					RequestBody: generateServer(t, map[string]interface{}{
+						"id":           GetServerId(t, "test-ds-server-assignments")(),
+						"cachegroupId": GetCacheGroupId(t, "cachegroup1")(),
+						"typeId":       GetTypeId(t, "MID"),
+					}),
+					Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+				},
+				"CONFLICT when UPDATING SERVER STATUS when its the ONLY EDGE SERVER ASSIGNED": {
+					EndpointId:    GetServerId(t, "test-ds-server-assignments"),
+					ClientSession: TOSession,
+					RequestBody: generateServer(t, map[string]interface{}{
+						"id":       GetServerId(t, "test-ds-server-assignments")(),
+						"statusId": GetStatusId(t, "ADMIN_DOWN")(),
+					}),
+					Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+				},
+				"BAD REQUEST when UPDATING CDN when LAST SERVER IN CACHEGROUP IN TOPOLOGY": {
+					EndpointId:    GetServerId(t, "midInTopologyMidCg01"),
+					ClientSession: TOSession,
+					RequestBody: generateServer(t, map[string]interface{}{
+						"id":           GetServerId(t, "midInTopologyMidCg01")(),
+						"cdnId":        GetCDNId(t, "cdn1"),
+						"profileId":    GetProfileId(t, "MID1"),
+						"cachegroupId": GetCacheGroupId(t, "topology-mid-cg-01")(),
+					}),
+					Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+				"BAD REQUEST when UPDATING CACHEGROUP when LAST SERVER IN CACHEGROUP IN TOPOLOGY": {
+					EndpointId:    GetServerId(t, "midInTopologyMidCg01"),
+					ClientSession: TOSession,
+					RequestBody: generateServer(t, map[string]interface{}{
+						"id":           GetServerId(t, "midInTopologyMidCg01")(),
+						"hostName":     "midInTopologyMidCg01",
+						"cdnId":        GetCDNId(t, "cdn2"),
+						"profileId":    GetProfileId(t, "CDN2_MID"),
+						"cachegroupId": GetCacheGroupId(t, "topology-mid-cg-02")(),
+					}),
+					Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+				"BAD REQUEST when IPADDRESS EXISTS with SAME PROFILE": {
+					EndpointId:    GetServerId(t, "atlanta-edge-16"),
+					ClientSession: TOSession,
+					RequestBody: generateServer(t, map[string]interface{}{
+						"profileNames": []string{"EDGE1"},
+						"interfaces": []map[string]interface{}{{
+							"ipAddresses": []map[string]interface{}{{
+								"address":        "127.0.0.11/22",
+								"gateway":        "127.0.0.11",
+								"serviceAddress": true,
+							}},
+							"name": "eth1",
+						}},
+					}),
+					Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+				"BAD REQUEST when BLANK HOSTNAME": {
+					EndpointId:    GetServerId(t, "atlanta-edge-16"),
+					ClientSession: TOSession,
+					RequestBody:   generateServer(t, map[string]interface{}{"hostName": ""}),
+					Expectations:  utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+				"BAD REQUEST when BLANK DOMAINNAME": {
+					EndpointId:    GetServerId(t, "atlanta-edge-16"),
+					ClientSession: TOSession,
+					RequestBody:   generateServer(t, map[string]interface{}{"domainName": ""}),
+					Expectations:  utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+				"PRECONDITION FAILED when updating with IMS & IUS Headers": {
+					EndpointId:     GetServerId(t, "atlanta-edge-01"),
+					ClientSession:  TOSession,
+					RequestHeaders: http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}},
+					RequestBody: generateServer(t, map[string]interface{}{
+						"id": GetServerId(t, "atlanta-edge-01")(),
+					}),
+					Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)),
+				},
+				"PRECONDITION FAILED when updating with IFMATCH ETAG Header": {
+					EndpointId:    GetServerId(t, "atlanta-edge-01"),
+					ClientSession: TOSession,
+					RequestBody: generateServer(t, map[string]interface{}{
+						"id": GetServerId(t, "atlanta-edge-01")(),
+					}),
+					RequestHeaders: http.Header{rfc.IfMatch: {rfc.ETag(currentTime)}},
+					Expectations:   utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)),
+				},
+			},
+			"DELETE": {
+				"BAD REQUEST when LAST SERVER in CACHE GROUP": {
+					EndpointId:    GetServerId(t, "midInTopologyMidCg01"),
+					ClientSession: TOSession,
+					Expectations:  utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)),
+				},
+				"CONFLICT when DELETING SERVER when its the ONLY EDGE SERVER ASSIGNED": {
+					EndpointId:    getServerID(t, "test-ds-server-assignments"),
+					ClientSession: TOSession,
+					Expectations:  utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusConflict)),
+				},
+			},
+			"GET AFTER CHANGES": {
+				"OK when CHANGES made": {
+					ClientSession:  TOSession,
+					RequestHeaders: http.Header{rfc.IfModifiedSince: {currentTimeRFC}},
+					Expectations:   utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
+				},
+			},
 		}
-	}
-	// Keeping the status same, perform an update and make sure that statusLastUpdated didnt change
-	remoteServer.StatusID = &originalStatusID
-
-	alerts, _, err := TOSession.UpdateServerByIDWithHdr(*remoteServer.ID, remoteServer, nil)
-	if err != nil {
-		t.Fatalf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", *remoteServer.ID, hostName, err, alerts)
-	}
-
-	resp, _, err = TOSession.GetServersWithHdr(&idParam, nil)
-	if err != nil {
-		t.Errorf("cannot GET Server by ID: %v - %v", *remoteServer.HostName, err)
-	}
-	if len(resp.Response) < 1 {
-		t.Fatalf("Expected at least one server to exist by hostname '%s'", hostName)
-	}
-	if len(resp.Response) > 1 {
-		t.Errorf("Expected exactly one server to exist by hostname '%s' - actual: %d", hostName, len(resp.Response))
-		t.Logf("Testing will proceed with server: %+v", resp.Response[0])
-	}
-
-	respServer := resp.Response[0]
-
-	if !remoteServer.StatusLastUpdated.Equal(*respServer.StatusLastUpdated) {
-		t.Errorf("since status didnt change, no change in 'StatusLastUpdated' time was expected. Difference observer: old value: %v, new value: %v",
-			remoteServer.StatusLastUpdated.String(), respServer.StatusLastUpdated.String())
-	}
 
-	// Changing the status, perform an update and make sure that statusLastUpdated changed
-	remoteServer.StatusID = &updatedStatusID
-
-	alerts, _, err = TOSession.UpdateServerByIDWithHdr(*remoteServer.ID, remoteServer, nil)
-	if err != nil {
-		t.Fatalf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", *remoteServer.ID, hostName, err, alerts)
-	}
-
-	resp, _, err = TOSession.GetServersWithHdr(&idParam, nil)
-	if err != nil {
-		t.Errorf("cannot GET Server by ID: %v - %v", *remoteServer.HostName, err)
-	}
-	if len(resp.Response) < 1 {
-		t.Fatalf("Expected at least one server to exist by hostname '%s'", hostName)
-	}
-	if len(resp.Response) > 1 {
-		t.Errorf("Expected exactly one server to exist by hostname '%s' - actual: %d", hostName, len(resp.Response))
-		t.Logf("Testing will proceed with server: %+v", resp.Response[0])
-	}
-
-	respServer = resp.Response[0]
-
-	if *remoteServer.StatusLastUpdated == *respServer.StatusLastUpdated {
-		t.Errorf("since status was changed, expected to see a time difference between the old and new 'StatusLastUpdated' values, got the same value")
-	}
-
-	// Changing the status, perform an update and make sure that statusLastUpdated changed
-	remoteServer.StatusID = &originalStatusID
-
-	alerts, _, err = TOSession.UpdateServerByIDWithHdr(*remoteServer.ID, remoteServer, nil)
-	if err != nil {
-		t.Fatalf("cannot UPDATE Server by ID %d (hostname '%s'): %v - %v", *remoteServer.ID, hostName, err, alerts)
-	}
-
-	resp, _, err = TOSession.GetServersWithHdr(&idParam, nil)
-	if err != nil {
-		t.Errorf("cannot GET Server by ID: %v - %v", *remoteServer.HostName, err)
-	}
-	if len(resp.Response) < 1 {
-		t.Fatalf("Expected at least one server to exist by hostname '%s'", hostName)
-	}
-	if len(resp.Response) > 1 {
-		t.Errorf("Expected exactly one server to exist by hostname '%s' - actual: %d", hostName, len(resp.Response))
-		t.Logf("Testing will proceed with server: %+v", resp.Response[0])
-	}
-
-	respServer = resp.Response[0]
+		for method, testCases := range methodTests {
+			t.Run(method, func(t *testing.T) {
+				for name, testCase := range testCases {
+					server := tc.ServerV30{}
+
+					if testCase.RequestBody != nil {
+						dat, err := json.Marshal(testCase.RequestBody)
+						assert.NoError(t, err, "Error occurred when marshalling request body: %v", err)
+						err = json.Unmarshal(dat, &server)
+						assert.NoError(t, err, "Error occurred when unmarshalling request body: %v", err)
+					}
+
+					switch method {
+					case "GET", "GET AFTER CHANGES":
+						t.Run(name, func(t *testing.T) {
+							resp, reqInf, err := testCase.ClientSession.GetServersWithHdr(&testCase.RequestParams, testCase.RequestHeaders)
+							for _, check := range testCase.Expectations {
+								check(t, reqInf, resp.Response, resp.Alerts, err)
+							}
+						})
+					case "POST":
+						t.Run(name, func(t *testing.T) {
+							alerts, reqInf, err := testCase.ClientSession.CreateServerWithHdr(server, testCase.RequestHeaders)
+							for _, check := range testCase.Expectations {
+								check(t, reqInf, nil, alerts, err)
+							}
+						})
+					case "PUT":
+						t.Run(name, func(t *testing.T) {
+							alerts, reqInf, err := testCase.ClientSession.UpdateServerByIDWithHdr(testCase.EndpointId(), server, testCase.RequestHeaders)
+							for _, check := range testCase.Expectations {
+								check(t, reqInf, nil, alerts, err)
+							}
+						})
+					case "DELETE":
+						t.Run(name, func(t *testing.T) {
+							alerts, reqInf, err := testCase.ClientSession.DeleteServerByID(testCase.EndpointId())
+							for _, check := range testCase.Expectations {
+								check(t, reqInf, nil, alerts, err)
+							}
+						})
+					}
+				}
+			})
+		}
+		t.Run("DS SERVER ASSIGNMENT REMOVED when DS UPDATED TO USE TOPOLOGY", func(t *testing.T) { UpdateDSGetServerDSID(t) })
+		t.Run("STATUSLASTUPDATED ONLY CHANGES when STATUS CHANGES", func(t *testing.T) { UpdateTestServerStatusLastUpdated(t) })
 
-	if *remoteServer.StatusLastUpdated == *respServer.StatusLastUpdated {
-		t.Errorf("since status was changed, expected to see a time difference between the old and new 'StatusLastUpdated' values, got the same value")
-	}
+	})
 }
 
-func UpdateTestServersWithHeaders(t *testing.T, header http.Header) {
-	if len(testData.Servers) < 1 {
-		t.Fatal("Need at least one server to test updating")
-	}
-
-	firstServer := testData.Servers[0]
-	if firstServer.HostName == nil {
-		t.Fatalf("First test server had nil hostname: %+v", firstServer)
-	}
-
-	hostName := *firstServer.HostName
-	params := url.Values{}
-	params.Add("hostName", hostName)
-
-	// Retrieve the server by hostname so we can get the id for the Update
-	resp, _, err := TOSession.GetServersWithHdr(&params, header)
-
-	if err != nil {
-		t.Fatalf("cannot GET Server by hostname '%s': %v - %v", hostName, err, resp.Alerts)
-	}
-	if len(resp.Response) < 1 {
-		t.Fatalf("Expected at least one server to exist by hostname '%s'", hostName)
-	}
-	if len(resp.Response) > 1 {
-		t.Errorf("Expected exactly one server to exist by hostname '%s' - actual: %d", hostName, len(resp.Response))
-		t.Logf("Testing will proceed with server: %+v", resp.Response[0])
-	}
-
-	remoteServer := resp.Response[0]
-	if remoteServer.ID == nil {
-		t.Fatalf("Got null ID for server '%s'", hostName)
-	}
-
-	// Creating idParam to get server when hostname changes.
-	id := fmt.Sprintf("%v", *resp.Response[0].ID)
-	idParam := url.Values{}
-	idParam.Add("id", id)
-
-	infs := remoteServer.Interfaces
-	if len(infs) < 1 {
-		t.Fatalf("Expected server '%s' to have at least one network interface", hostName)
-	}
-	inf := infs[0]
-
-	updatedServerInterface := "bond1"
-	updatedServerRack := "RR 119.03"
-	updatedHostName := "atl-edge-01"
-
-	// update rack, interfaceName and hostName values on server
-	inf.Name = updatedServerInterface
-	infs[0] = inf
-	remoteServer.Interfaces = infs
-	remoteServer.Rack = &updatedServerRack
-	remoteServer.HostName = &updatedHostName
-
-	_, reqInf, err := TOSession.UpdateServerByIDWithHdr(*remoteServer.ID, remoteServer, header)
-	if err == nil {
-		t.Errorf("Expected error about precondition failed, but got none")
-	}
-	if reqInf.StatusCode != http.StatusPreconditionFailed {
-		t.Errorf("Expected status code 412, got %v", reqInf.StatusCode)
+func validateServerFields(expectedResp map[string]interface{}) utils.CkReqFunc {
+	return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
+		assert.RequireNotNil(t, resp, "Expected response to not be nil.")
+		serverResp := resp.([]tc.ServerV30)

Review Comment:
   You're right. That's not supposed to happen; each major version should have an alias for the latest minor version and that's what the client is supposed to be using. But that's not your PR's fault, so `ServerV30` is the right choice here.



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org