This is an automated email from the ASF dual-hosted git repository. mitchell852 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
commit 73e9661a350489e8242ad9fd7df1a3592a6c35ce Author: Dewayne Richardson <dewr...@apache.org> AuthorDate: Wed Apr 11 08:58:43 2018 -0600 created the PhysLocations API Tests --- traffic_ops/client/v13/phys_location.go | 4 +- traffic_ops/testing/api/v13/phys_locations_test.go | 111 +++++++++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/traffic_ops/client/v13/phys_location.go b/traffic_ops/client/v13/phys_location.go index 1083b18..259af30 100644 --- a/traffic_ops/client/v13/phys_location.go +++ b/traffic_ops/client/v13/phys_location.go @@ -25,7 +25,7 @@ import ( ) const ( - API_v13_PhysLocations = "/api/1.3/physlocations" + API_v13_PhysLocations = "/api/1.3/phys_locations" ) // Create a PhysLocation @@ -101,7 +101,7 @@ func (to *Session) GetPhysLocationByID(id int) ([]tc.PhysLocation, ReqInf, error // GET a PhysLocation by the PhysLocation name func (to *Session) GetPhysLocationByName(name string) ([]tc.PhysLocation, ReqInf, error) { - url := fmt.Sprintf("%s/name/%s", API_v13_PhysLocations, name) + url := fmt.Sprintf("%s?name=%s", API_v13_PhysLocations, name) resp, remoteAddr, err := to.request(http.MethodGet, url, nil) reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} if err != nil { diff --git a/traffic_ops/testing/api/v13/phys_locations_test.go b/traffic_ops/testing/api/v13/phys_locations_test.go new file mode 100644 index 0000000..67f1164 --- /dev/null +++ b/traffic_ops/testing/api/v13/phys_locations_test.go @@ -0,0 +1,111 @@ +package v13 + +/* + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import ( + "testing" + + "github.com/apache/incubator-trafficcontrol/lib/go-log" + tc "github.com/apache/incubator-trafficcontrol/lib/go-tc" +) + +func TestPhysLocations(t *testing.T) { + + CreateTestPhysLocations(t) + UpdateTestPhysLocations(t) + GetTestPhysLocations(t) + DeleteTestPhysLocations(t) + +} + +func CreateTestPhysLocations(t *testing.T) { + + for _, cdn := range testData.PhysLocations { + resp, _, err := TOSession.CreatePhysLocation(cdn) + log.Debugln("Response: ", resp) + if err != nil { + t.Errorf("could not CREATE cdns: %v\n", err) + } + } + +} + +func UpdateTestPhysLocations(t *testing.T) { + + firstPhysLocation := testData.PhysLocations[0] + // Retrieve the PhysLocation by name so we can get the id for the Update + resp, _, err := TOSession.GetPhysLocationByName(firstPhysLocation.Name) + if err != nil { + t.Errorf("cannot GET PhysLocation by name: '%s', %v\n", firstPhysLocation.Name, err) + } + remotePhysLocation := resp[0] + expectedPhysLocationCity := "city1" + remotePhysLocation.City = expectedPhysLocationCity + var alert tc.Alerts + alert, _, err = TOSession.UpdatePhysLocationByID(remotePhysLocation.ID, remotePhysLocation) + if err != nil { + t.Errorf("cannot UPDATE PhysLocation by id: %v - %v\n", err, alert) + } + + // Retrieve the PhysLocation to check PhysLocation name got updated + resp, _, err = TOSession.GetPhysLocationByID(remotePhysLocation.ID) + if err != nil { + t.Errorf("cannot GET PhysLocation by name: '$%s', %v\n", firstPhysLocation.Name, err) + } + respPhysLocation := resp[0] + if respPhysLocation.City != expectedPhysLocationCity { + t.Errorf("results do not match actual: %s, expected: %s\n", respPhysLocation.City, expectedPhysLocationCity) + } + +} + +func GetTestPhysLocations(t *testing.T) { + + for _, cdn := range testData.PhysLocations { + resp, _, err := TOSession.GetPhysLocationByName(cdn.Name) + if err != nil { + t.Errorf("cannot GET PhysLocation by name: %v - %v\n", err, resp) + } + } +} + +func DeleteTestPhysLocations(t *testing.T) { + + for _, cdn := range testData.PhysLocations { + // Retrieve the PhysLocation by name so we can get the id for the Update + resp, _, err := TOSession.GetPhysLocationByName(cdn.Name) + if err != nil { + t.Errorf("cannot GET PhysLocation by name: %v - %v\n", cdn.Name, err) + } + if len(resp) > 0 { + respPhysLocation := resp[0] + + _, _, err := TOSession.DeletePhysLocationByID(respPhysLocation.ID) + if err != nil { + t.Errorf("cannot DELETE PhysLocation by name: '%s' %v\n", respPhysLocation.Name, err) + } + + // Retrieve the PhysLocation to see if it got deleted + cdns, _, err := TOSession.GetPhysLocationByName(cdn.Name) + if err != nil { + t.Errorf("error deleting PhysLocation name: %s\n", err.Error()) + } + if len(cdns) > 0 { + t.Errorf("expected PhysLocation name: %s to be deleted\n", cdn.Name) + } + } + } +} -- To stop receiving notification emails like this one, please contact mitchell...@apache.org.