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

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


The following commit(s) were added to refs/heads/master by this push:
     new fc3777e  TO: Fix 404 errors (#3565)
fc3777e is described below

commit fc3777e7ea05e3bd56a6847ddca9df78b6f5d97a
Author: Matthew Allen Moltzau <[email protected]>
AuthorDate: Wed May 15 11:10:55 2019 -0600

    TO: Fix 404 errors (#3565)
    
    * Fix 404 origins error
    
    * Fixed 404 steering targets error
    
    * Added simple 404 not found test for origins
---
 traffic_ops/testing/api/v14/origins_test.go                  |  9 +++++++++
 traffic_ops/traffic_ops_golang/origin/origins.go             | 12 +++++++-----
 .../traffic_ops_golang/steeringtargets/steeringtargets.go    |  4 ++--
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/traffic_ops/testing/api/v14/origins_test.go 
b/traffic_ops/testing/api/v14/origins_test.go
index c31634c..03d0425 100644
--- a/traffic_ops/testing/api/v14/origins_test.go
+++ b/traffic_ops/testing/api/v14/origins_test.go
@@ -16,6 +16,7 @@ package v14
 */
 
 import (
+       "strings"
        "testing"
        "time"
 
@@ -28,6 +29,7 @@ func TestOrigins(t *testing.T) {
        WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles, 
Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Users, 
DeliveryServices, Coordinates, Origins}, func() {
                UpdateTestOrigins(t)
                GetTestOrigins(t)
+               NotFoundDeleteTest(t)
                OriginTenancyTest(t)
        })
 }
@@ -42,6 +44,13 @@ func CreateTestOrigins(t *testing.T) {
        }
 }
 
+func NotFoundDeleteTest(t *testing.T) {
+       _, _, err := TOSession.DeleteOriginByID(2020)
+       if !strings.Contains(err.Error(), "not found") {
+               t.Errorf("deleted origin with what should be a non-existent 
id\n")
+       }
+}
+
 func GetTestOrigins(t *testing.T) {
        _, _, err := TOSession.GetOrigins()
        if err != nil {
diff --git a/traffic_ops/traffic_ops_golang/origin/origins.go 
b/traffic_ops/traffic_ops_golang/origin/origins.go
index d11deb7..15cf341 100644
--- a/traffic_ops/traffic_ops_golang/origin/origins.go
+++ b/traffic_ops/traffic_ops_golang/origin/origins.go
@@ -275,6 +275,9 @@ func (origin *TOOrigin) Update() (error, error, int) {
        ds := 0
        q := `SELECT is_primary, deliveryservice FROM origin WHERE id = $1`
        if err := origin.ReqInfo.Tx.QueryRow(q, *origin.ID).Scan(&isPrimary, 
&ds); err != nil {
+               if err == sql.ErrNoRows {
+                       return errors.New("origin not found"), nil, 
http.StatusNotFound
+               }
                return nil, errors.New("origin update: querying: " + 
err.Error()), http.StatusInternalServerError
        }
        if isPrimary && *origin.DeliveryServiceID != ds {
@@ -397,6 +400,9 @@ func (origin *TOOrigin) Delete() (error, error, int) {
        isPrimary := false
        q := `SELECT is_primary FROM origin WHERE id = $1`
        if err := origin.ReqInfo.Tx.QueryRow(q, *origin.ID).Scan(&isPrimary); 
err != nil {
+               if err == sql.ErrNoRows {
+                       return errors.New("origin not found"), nil, 
http.StatusNotFound
+               }
                return nil, errors.New("origin delete: is_primary scanning: " + 
err.Error()), http.StatusInternalServerError
        }
        if isPrimary {
@@ -412,11 +418,7 @@ func (origin *TOOrigin) Delete() (error, error, int) {
                return nil, errors.New("origin delete: getting rows affected: " 
+ err.Error()), http.StatusInternalServerError
        }
        if rowsAffected != 1 {
-               if rowsAffected < 1 {
-                       return nil, nil, http.StatusNotFound
-               } else {
-                       return nil, errors.New("origin delete: multiple rows 
affected"), http.StatusInternalServerError
-               }
+               return nil, errors.New("origin delete: multiple rows 
affected"), http.StatusInternalServerError
        }
 
        return nil, nil, http.StatusOK
diff --git a/traffic_ops/traffic_ops_golang/steeringtargets/steeringtargets.go 
b/traffic_ops/traffic_ops_golang/steeringtargets/steeringtargets.go
index e6a46c7..d876c4b 100644
--- a/traffic_ops/traffic_ops_golang/steeringtargets/steeringtargets.go
+++ b/traffic_ops/traffic_ops_golang/steeringtargets/steeringtargets.go
@@ -234,7 +234,7 @@ func (st *TOSteeringTargetV11) Update() (error, error, int) 
{
        st.LastUpdated = &lastUpdated
        if rowsAffected != 1 {
                if rowsAffected < 1 {
-                       return nil, nil, http.StatusNotFound
+                       return errors.New("steering target not found"), nil, 
http.StatusNotFound
                }
                return nil, errors.New("too many ids returned from steering 
target update"), http.StatusInternalServerError
        }
@@ -256,7 +256,7 @@ func (st *TOSteeringTargetV11) Delete() (error, error, int) 
{
        }
 
        if rowsAffected < 1 {
-               return nil, nil, http.StatusNotFound
+               return errors.New("steering target not found"), nil, 
http.StatusNotFound
        } else if rowsAffected != 1 {
                return nil, fmt.Errorf("this create affected too many rows: 
%d", rowsAffected), http.StatusInternalServerError
        }

Reply via email to