Skip to content

Commit

Permalink
Integration Test Case updates for apache#7630
Browse files Browse the repository at this point in the history
  • Loading branch information
jagan-parthiban committed Jul 14, 2023
1 parent 5611399 commit 1de3d33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions traffic_ops/testing/api/v5/phys_locations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestPhysLocations(t *testing.T) {
currentTimeRFC := currentTime.Format(time.RFC1123)
tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)

methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.PhysLocation]{
methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.PhysLocationV5]{
"GET": {
"NOT MODIFIED when NO CHANGES made": {
ClientSession: TOSession,
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestPhysLocations(t *testing.T) {
"POST": {
"OK when VALID request": {
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "100 blah lane",
City: "foo",
Comments: "comment",
Expand All @@ -112,12 +112,12 @@ func TestPhysLocations(t *testing.T) {
State: "CO",
Zip: "80602",
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusCreated),
validatePhysicalLocationUpdateCreateFields("testPhysicalLocation", map[string]interface{}{"Name": "testPhysicalLocation"})),
},
"BAD REQUEST when REGION ID does NOT MATCH REGION NAME": {
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "Atlanta",
Name: "HotAtlanta",
Expand All @@ -135,7 +135,7 @@ func TestPhysLocations(t *testing.T) {
"OK when VALID request": {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "NewCity",
Name: "HotAtlanta",
Expand All @@ -152,7 +152,7 @@ func TestPhysLocations(t *testing.T) {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}}},
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "Atlanta",
RegionID: GetRegionID(t, "region1")(),
Expand All @@ -166,7 +166,7 @@ func TestPhysLocations(t *testing.T) {
"PRECONDITION FAILED when updating with IFMATCH ETAG Header": {
EndpointID: GetPhysicalLocationID(t, "HotAtlanta"),
ClientSession: TOSession,
RequestBody: tc.PhysLocation{
RequestBody: tc.PhysLocationV5{
Address: "1234 southern way",
City: "Atlanta",
RegionID: GetRegionID(t, "region1")(),
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestPhysLocations(t *testing.T) {
func validatePhysicalLocationFields(expectedResp map[string]interface{}) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Physical Location response to not be nil.")
plResp := resp.([]tc.PhysLocation)
plResp := resp.([]tc.PhysLocationV5)
for field, expected := range expectedResp {
for _, pl := range plResp {
switch field {
Expand Down Expand Up @@ -259,7 +259,7 @@ func validatePhysicalLocationUpdateCreateFields(name string, expectedResp map[st

func validatePhysicalLocationPagination(paginationParam string) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
paginationResp := resp.([]tc.PhysLocation)
paginationResp := resp.([]tc.PhysLocationV5)

opts := client.NewRequestOptions()
opts.QueryParameters.Set("orderby", "id")
Expand All @@ -283,7 +283,7 @@ func validatePhysicalLocationSort() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, alerts tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Physical Location response to not be nil.")
var physLocNames []string
physLocResp := resp.([]tc.PhysLocation)
physLocResp := resp.([]tc.PhysLocationV5)
for _, pl := range physLocResp {
physLocNames = append(physLocNames, pl.Name)
}
Expand All @@ -295,7 +295,7 @@ func validatePhysicalLocationIDSort() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, alerts tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Physical Location response to not be nil.")
var physLocIDs []int
physLocResp := resp.([]tc.PhysLocation)
physLocResp := resp.([]tc.PhysLocationV5)
for _, pl := range physLocResp {
physLocIDs = append(physLocIDs, pl.ID)
}
Expand Down
2 changes: 1 addition & 1 deletion traffic_ops/testing/api/v5/traffic_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type TrafficControl struct {
Profiles []tc.Profile `json:"profiles"`
Parameters []tc.Parameter `json:"parameters"`
ProfileParameters []tc.ProfileParameter `json:"profileParameters"`
PhysLocations []tc.PhysLocation `json:"physLocations"`
PhysLocations []tc.PhysLocationV5 `json:"physLocations"`
Regions []tc.Region `json:"regions"`
Roles []tc.RoleV4 `json:"roles"`
Servers []tc.ServerV4 `json:"servers"`
Expand Down
8 changes: 4 additions & 4 deletions traffic_ops/v5-client/phys_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
const apiPhysLocations = "/phys_locations"

// CreatePhysLocation creates the passed Physical Location.
func (to *Session) CreatePhysLocation(pl tc.PhysLocation, opts RequestOptions) (tc.Alerts, toclientlib.ReqInf, error) {
func (to *Session) CreatePhysLocation(pl tc.PhysLocationV5, opts RequestOptions) (tc.Alerts, toclientlib.ReqInf, error) {
if pl.RegionID == 0 && pl.RegionName != "" {
regionOpts := NewRequestOptions()
regionOpts.QueryParameters.Set("name", pl.RegionName)
Expand All @@ -47,16 +47,16 @@ func (to *Session) CreatePhysLocation(pl tc.PhysLocation, opts RequestOptions) (

// UpdatePhysLocation replaces the Physical Location identified by 'id' with
// the given Physical Location structure.
func (to *Session) UpdatePhysLocation(id int, pl tc.PhysLocation, opts RequestOptions) (tc.Alerts, toclientlib.ReqInf, error) {
func (to *Session) UpdatePhysLocation(id int, pl tc.PhysLocationV5, opts RequestOptions) (tc.Alerts, toclientlib.ReqInf, error) {
route := fmt.Sprintf("%s/%d", apiPhysLocations, id)
var alerts tc.Alerts
reqInf, err := to.put(route, opts, pl, &alerts)
return alerts, reqInf, err
}

// GetPhysLocations retrieves Physical Locations from Traffic Ops.
func (to *Session) GetPhysLocations(opts RequestOptions) (tc.PhysLocationsResponse, toclientlib.ReqInf, error) {
var data tc.PhysLocationsResponse
func (to *Session) GetPhysLocations(opts RequestOptions) (tc.PhysLocationsResponseV5, toclientlib.ReqInf, error) {
var data tc.PhysLocationsResponseV5
reqInf, err := to.get(apiPhysLocations, opts, &data)
return data, reqInf, err
}
Expand Down

0 comments on commit 1de3d33

Please sign in to comment.