dewrich closed pull request #1960: TO golang asns point fixes
URL: https://github.com/apache/incubator-trafficcontrol/pull/1960
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lib/go-tc/asns.go b/lib/go-tc/asns.go
index ac73a57dcb..8bc967a9d6 100644
--- a/lib/go-tc/asns.go
+++ b/lib/go-tc/asns.go
@@ -25,7 +25,7 @@ type ASNsResponse struct {
 
 type ASN struct {
        ASN          int       `json:"asn" db:"asn"`
-       Cachegroup   string    `json:"cachegroup" db:"cachegroup"`
+       Cachegroup   string    `json:"cachegroup"`
        CachegroupID int       `json:"cachegroupId" db:"cachegroup_id"`
        ID           int       `json:"id" db:"id"`
        LastUpdated  TimeNoMod `json:"lastUpdated" db:"last_updated"`
@@ -33,7 +33,7 @@ type ASN struct {
 
 type ASNNullable struct {
        ASN          *int       `json:"asn" db:"asn"`
-       Cachegroup   *string    `json:"cachegroup" db:"cachegroup"`
+       Cachegroup   *string    `json:"cachegroup"`
        CachegroupID *int       `json:"cachegroupId" db:"cachegroup_id"`
        ID           *int       `json:"id" db:"id"`
        LastUpdated  *TimeNoMod `json:"lastUpdated" db:"last_updated"`
diff --git a/traffic_ops/traffic_ops_golang/asn/asns.go 
b/traffic_ops/traffic_ops_golang/asn/asns.go
index ecc2c56f9f..4833aad492 100644
--- a/traffic_ops/traffic_ops_golang/asn/asns.go
+++ b/traffic_ops/traffic_ops_golang/asn/asns.go
@@ -155,9 +155,10 @@ func (asn *TOASN) Read(db *sqlx.DB, parameters 
map[string]string, user auth.Curr
        // Query Parameters to Database Query column mappings
        // see the fields mapped in the SQL query
        queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-               "asn":        dbhelpers.WhereColumnInfo{"a.asn", nil},
-               "cachegroup": dbhelpers.WhereColumnInfo{"c.name", nil},
-               "id":         dbhelpers.WhereColumnInfo{"a.id", api.IsInt},
+               "asn":            dbhelpers.WhereColumnInfo{"a.asn", nil},
+               "cachegroup":     dbhelpers.WhereColumnInfo{"c.id", nil},
+               "id":             dbhelpers.WhereColumnInfo{"a.id", api.IsInt},
+               "cachegroupName": dbhelpers.WhereColumnInfo{"c.name", nil},
        }
        where, orderBy, queryValues, errs := 
dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
        if len(errs) > 0 {
@@ -170,16 +171,16 @@ func (asn *TOASN) Read(db *sqlx.DB, parameters 
map[string]string, user auth.Curr
        rows, err := db.NamedQuery(query, queryValues)
        if err != nil {
                log.Errorf("Error querying ASNs: %v", err)
-               return nil, []error{tc.DBError}, tc.SystemError
+               return nil, []error{err}, tc.SystemError
        }
        defer rows.Close()
 
        ASNs := []interface{}{}
        for rows.Next() {
-               var s tc.ASN
+               var s TOASN
                if err = rows.StructScan(&s); err != nil {
                        log.Errorf("error parsing ASN rows: %v", err)
-                       return nil, []error{tc.DBError}, tc.SystemError
+                       return nil, []error{err}, tc.SystemError
                }
                ASNs = append(ASNs, s)
        }
@@ -315,9 +316,8 @@ asn,
 cachegroup) 
 VALUES (
 :asn,
-(SELECT id from cachegroup
-WHERE name=:cachegroup
-))
+:cachegroup_id
+)
 RETURNING id,last_updated`
        return query
 }
@@ -326,9 +326,7 @@ func updateQuery() string {
        query := `UPDATE
 asn SET
 asn=:asn,
-cachegroup=(SELECT id from cachegroup
-WHERE name=:cachegroup
-)
+cachegroup=:cachegroup_id
 WHERE id=:id RETURNING last_updated`
        return query
 }
diff --git a/traffic_ops/traffic_ops_golang/asn/asns_test.go 
b/traffic_ops/traffic_ops_golang/asn/asns_test.go
index dcb0a3b7ea..6c500ff1e7 100644
--- a/traffic_ops/traffic_ops_golang/asn/asns_test.go
+++ b/traffic_ops/traffic_ops_golang/asn/asns_test.go
@@ -34,18 +34,21 @@ import (
        sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
 )
 
-func getTestASNs() []tc.ASN {
-       ASNs := []tc.ASN{}
-       testCase := tc.ASN{
-               ASN:         1,
-               Cachegroup:  "Yukon",
-               ID:          1,
-               LastUpdated: tc.TimeNoMod{Time: time.Now()},
+func getTestASNs() []TOASN {
+       ASNs := []TOASN{}
+       i := 1
+       c := "Yukon"
+       testCase := TOASN{
+               ASN:          &i,
+               Cachegroup:   &c,
+               CachegroupID: &i,
+               ID:           &i,
+               LastUpdated:  &tc.TimeNoMod{Time: time.Now()},
        }
        ASNs = append(ASNs, testCase)
 
        testCase2 := testCase
-       testCase2.ASN = 2
+       *testCase2.ASN = 2
        ASNs = append(ASNs, testCase2)
 
        return ASNs
@@ -62,16 +65,15 @@ func TestGetASNs(t *testing.T) {
        defer db.Close()
 
        testCase := getTestASNs()
-       cols := test.ColsFromStructByTag("db", tc.ASN{})
+       cols := test.ColsFromStructByTag("db", TOASN{})
        rows := sqlmock.NewRows(cols)
 
        for _, ts := range testCase {
                rows = rows.AddRow(
-                       ts.ASN,
-                       ts.Cachegroup,
-                       ts.CachegroupID,
-                       ts.ID,
-                       ts.LastUpdated,
+                       *ts.ASN,
+                       *ts.CachegroupID,
+                       *ts.ID,
+                       *ts.LastUpdated,
                )
        }
        mock.ExpectQuery("SELECT").WillReturnRows(rows)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to