This is an automated email from the ASF dual-hosted git repository. dangogh pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
commit 841a6209a86d8f8df03565de1c800fbee40fbae6 Author: Dewayne Richardson <dewr...@apache.org> AuthorDate: Thu Feb 22 12:16:06 2018 -0700 added division creation to link up foreign keys removed debug refactored to support TO Client versioning with packages added initial cachegroups API test and added v13 package fixed conflicts temporarily removed to allow to compile fixed merge conflicts --- traffic_ops/testing/api/v13/division_test.go | 107 ----------------------- traffic_ops/testing/api/v13/region_test.go | 107 ----------------------- traffic_ops/testing/api/v13/status_test.go | 106 ---------------------- traffic_ops/traffic_ops_golang/region/regions.go | 92 ------------------- 4 files changed, 412 deletions(-) diff --git a/traffic_ops/testing/api/v13/division_test.go b/traffic_ops/testing/api/v13/division_test.go deleted file mode 100644 index aa72293..0000000 --- a/traffic_ops/testing/api/v13/division_test.go +++ /dev/null @@ -1,107 +0,0 @@ -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 ( - "fmt" - "testing" - - "github.com/apache/incubator-trafficcontrol/lib/go-log" - "github.com/apache/incubator-trafficcontrol/lib/go-tc" -) - -func TestDivisions(t *testing.T) { - - CreateTestDivisions(t) - UpdateTestDivisions(t) - GetTestDivisions(t) - DeleteTestDivisions(t) - -} - -func CreateTestDivisions(t *testing.T) { - for _, division := range testData.Divisions { - fmt.Printf("division ---> %v\n", division) - resp, _, err := TOSession.CreateDivision(division) - log.Debugln("Response: ", resp) - if err != nil { - t.Errorf("could not CREATE division: %v\n", err) - } - } -} - -func UpdateTestDivisions(t *testing.T) { - - firstDivision := testData.Divisions[0] - // Retrieve the Division by division so we can get the id for the Update - resp, _, err := TOSession.GetDivisionByName(firstDivision.Name) - if err != nil { - t.Errorf("cannot GET Division by division: %v - %v\n", firstDivision.Name, err) - } - remoteDivision := resp[0] - expectedDivision := "division-test" - remoteDivision.Name = expectedDivision - var alert tc.Alerts - alert, _, err = TOSession.UpdateDivisionByID(remoteDivision.ID, remoteDivision) - if err != nil { - t.Errorf("cannot UPDATE Division by id: %v - %v\n", err, alert) - } - - // Retrieve the Division to check division got updated - resp, _, err = TOSession.GetDivisionByID(remoteDivision.ID) - if err != nil { - t.Errorf("cannot GET Division by division: %v - %v\n", firstDivision.Name, err) - } - respDivision := resp[0] - if respDivision.Name != expectedDivision { - t.Errorf("results do not match actual: %s, expected: %s\n", respDivision.Name, expectedDivision) - } - -} - -func GetTestDivisions(t *testing.T) { - for _, division := range testData.Divisions { - resp, _, err := TOSession.GetDivisionByName(division.Name) - if err != nil { - t.Errorf("cannot GET Division by division: %v - %v\n", err, resp) - } - } -} - -func DeleteTestDivisions(t *testing.T) { - - division := testData.Divisions[1] - // Retrieve the Division by name so we can get the id - resp, _, err := TOSession.GetDivisionByName(division.Name) - if err != nil { - t.Errorf("cannot GET Division by name: %v - %v\n", division.Name, err) - } - respDivision := resp[0] - - delResp, _, err := TOSession.DeleteDivisionByID(respDivision.ID) - if err != nil { - t.Errorf("cannot DELETE Division by division: %v - %v\n", err, delResp) - } - - // Retrieve the Division to see if it got deleted - divisionResp, _, err := TOSession.GetDivisionByName(division.Name) - if err != nil { - t.Errorf("error deleting Division division: %s\n", err.Error()) - } - if len(divisionResp) > 0 { - t.Errorf("expected Division : %s to be deleted\n", division.Name) - } -} diff --git a/traffic_ops/testing/api/v13/region_test.go b/traffic_ops/testing/api/v13/region_test.go deleted file mode 100644 index 7eaba11..0000000 --- a/traffic_ops/testing/api/v13/region_test.go +++ /dev/null @@ -1,107 +0,0 @@ -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 ( - "fmt" - "testing" - - "github.com/apache/incubator-trafficcontrol/lib/go-log" - "github.com/apache/incubator-trafficcontrol/lib/go-tc" -) - -func TestRegions(t *testing.T) { - - CreateTestRegions(t) - UpdateTestRegions(t) - GetTestRegions(t) - DeleteTestRegions(t) - -} - -func CreateTestRegions(t *testing.T) { - for _, region := range testData.Regions { - fmt.Printf("region ---> %v\n", region) - resp, _, err := TOSession.CreateRegion(region) - log.Debugln("Response: ", resp) - if err != nil { - t.Errorf("could not CREATE region: %v\n", err) - } - } -} - -func UpdateTestRegions(t *testing.T) { - - firstRegion := testData.Regions[0] - // Retrieve the Region by region so we can get the id for the Update - resp, _, err := TOSession.GetRegionByName(firstRegion.Name) - if err != nil { - t.Errorf("cannot GET Region by region: %v - %v\n", firstRegion.Name, err) - } - remoteRegion := resp[0] - expectedRegion := "OFFLINE-TEST" - remoteRegion.Name = expectedRegion - var alert tc.Alerts - alert, _, err = TOSession.UpdateRegionByID(remoteRegion.ID, remoteRegion) - if err != nil { - t.Errorf("cannot UPDATE Region by id: %v - %v\n", err, alert) - } - - // Retrieve the Region to check region got updated - resp, _, err = TOSession.GetRegionByID(remoteRegion.ID) - if err != nil { - t.Errorf("cannot GET Region by region: %v - %v\n", firstRegion.Name, err) - } - respRegion := resp[0] - if respRegion.Name != expectedRegion { - t.Errorf("results do not match actual: %s, expected: %s\n", respRegion.Name, expectedRegion) - } - -} - -func GetTestRegions(t *testing.T) { - for _, region := range testData.Regions { - resp, _, err := TOSession.GetRegionByName(region.Name) - if err != nil { - t.Errorf("cannot GET Region by region: %v - %v\n", err, resp) - } - } -} - -func DeleteTestRegions(t *testing.T) { - - region := testData.Regions[1] - // Retrieve the Region by name so we can get the id - resp, _, err := TOSession.GetRegionByName(region.Name) - if err != nil { - t.Errorf("cannot GET Region by name: %v - %v\n", region.Name, err) - } - respRegion := resp[0] - - delResp, _, err := TOSession.DeleteRegionByID(respRegion.ID) - if err != nil { - t.Errorf("cannot DELETE Region by region: %v - %v\n", err, delResp) - } - - // Retrieve the Region to see if it got deleted - regionResp, _, err := TOSession.GetRegionByName(region.Name) - if err != nil { - t.Errorf("error deleting Region region: %s\n", err.Error()) - } - if len(regionResp) > 0 { - t.Errorf("expected Region : %s to be deleted\n", region.Name) - } -} diff --git a/traffic_ops/testing/api/v13/status_test.go b/traffic_ops/testing/api/v13/status_test.go deleted file mode 100644 index 6478001..0000000 --- a/traffic_ops/testing/api/v13/status_test.go +++ /dev/null @@ -1,106 +0,0 @@ -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" - "github.com/apache/incubator-trafficcontrol/lib/go-tc" -) - -func TestStatuses(t *testing.T) { - - CreateTestStatuses(t) - UpdateTestStatuses(t) - GetTestStatuses(t) - DeleteTestStatuses(t) - -} - -func CreateTestStatuses(t *testing.T) { - for _, status := range testData.Statuses { - resp, _, err := TOSession.CreateStatus(status) - log.Debugln("Response: ", resp) - if err != nil { - t.Errorf("could not CREATE statuss: %v\n", err) - } - } - -} - -func UpdateTestStatuses(t *testing.T) { - - firstStatus := testData.Statuses[0] - // Retrieve the Status by status so we can get the id for the Update - resp, _, err := TOSession.GetStatusByName(firstStatus.Name) - if err != nil { - t.Errorf("cannot GET Status by status: %v - %v\n", firstStatus.Name, err) - } - remoteStatus := resp[0] - expectedStatus := "OFFLINE-TEST" - remoteStatus.Name = expectedStatus - var alert tc.Alerts - alert, _, err = TOSession.UpdateStatusByID(remoteStatus.ID, remoteStatus) - if err != nil { - t.Errorf("cannot UPDATE Status by id: %v - %v\n", err, alert) - } - - // Retrieve the Status to check status got updated - resp, _, err = TOSession.GetStatusByID(remoteStatus.ID) - if err != nil { - t.Errorf("cannot GET Status by status: %v - %v\n", firstStatus.Name, err) - } - respStatus := resp[0] - if respStatus.Name != expectedStatus { - t.Errorf("results do not match actual: %s, expected: %s\n", respStatus.Name, expectedStatus) - } - -} - -func GetTestStatuses(t *testing.T) { - for _, status := range testData.Statuses { - resp, _, err := TOSession.GetStatusByName(status.Name) - if err != nil { - t.Errorf("cannot GET Status by status: %v - %v\n", err, resp) - } - } -} - -func DeleteTestStatuses(t *testing.T) { - - status := testData.Statuses[1] - // Retrieve the Status by name so we can get the id - resp, _, err := TOSession.GetStatusByName(status.Name) - if err != nil { - t.Errorf("cannot GET Status by name: %v - %v\n", status.Name, err) - } - respStatus := resp[0] - - delResp, _, err := TOSession.DeleteStatusByID(respStatus.ID) - if err != nil { - t.Errorf("cannot DELETE Status by status: %v - %v\n", err, delResp) - } - - // Retrieve the Status to see if it got deleted - statusResp, _, err := TOSession.GetStatusByName(status.Name) - if err != nil { - t.Errorf("error deleting Status status: %s\n", err.Error()) - } - if len(statusResp) > 0 { - t.Errorf("expected Status status: %s to be deleted\n", status.Name) - } -} diff --git a/traffic_ops/traffic_ops_golang/region/regions.go b/traffic_ops/traffic_ops_golang/region/regions.go index 331fd2c..52d881d 100644 --- a/traffic_ops/traffic_ops_golang/region/regions.go +++ b/traffic_ops/traffic_ops_golang/region/regions.go @@ -43,13 +43,8 @@ func GetRefType() *TORegion { } //Implementation of the Identifier, Validator interface functions -<<<<<<< HEAD func (region *TORegion) GetID() (int, bool) { return region.ID, true -======= -func (region *TORegion) GetID() int { - return region.ID ->>>>>>> updated to use the CRUD interface } func (region *TORegion) GetAuditName() string { @@ -78,27 +73,16 @@ func (region *TORegion) Read(db *sqlx.DB, parameters map[string]string, user aut // Query Parameters to Database Query column mappings // see the fields mapped in the SQL query queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{ -<<<<<<< HEAD "name": dbhelpers.WhereColumnInfo{"r.name", nil}, "division": dbhelpers.WhereColumnInfo{"r.division", nil}, "id": dbhelpers.WhereColumnInfo{"r.id", api.IsInt}, -======= - "domainName": dbhelpers.WhereColumnInfo{"domain_name", nil}, - "dnssecEnabled": dbhelpers.WhereColumnInfo{"dnssec_enabled", nil}, - "id": dbhelpers.WhereColumnInfo{"id", api.IsInt}, - "name": dbhelpers.WhereColumnInfo{"name", nil}, ->>>>>>> updated to use the CRUD interface } where, orderBy, queryValues, errs := dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols) if len(errs) > 0 { return nil, errs, tc.DataConflictError } -<<<<<<< HEAD query := selectQuery() + where + orderBy -======= - query := selectRegionsQuery() + where + orderBy ->>>>>>> updated to use the CRUD interface log.Debugln("Query is ", query) rows, err := db.NamedQuery(query, queryValues) @@ -108,18 +92,13 @@ func (region *TORegion) Read(db *sqlx.DB, parameters map[string]string, user aut } defer rows.Close() -<<<<<<< HEAD regions := []interface{}{} -======= - Regions := []interface{}{} ->>>>>>> updated to use the CRUD interface for rows.Next() { var s tc.Region if err = rows.StructScan(&s); err != nil { log.Errorf("error parsing Region rows: %v", err) return nil, []error{tc.DBError}, tc.SystemError } -<<<<<<< HEAD regions = append(regions, s) } @@ -136,23 +115,6 @@ r.last_updated, r.name FROM region r JOIN division d ON r.division = d.id` -======= - Regions = append(Regions, s) - } - - return Regions, []error{}, tc.NoError -} - -func selectRegionsQuery() string { - query := `SELECT -description, -division, -id, -last_updated, -name - -FROM region r` ->>>>>>> updated to use the CRUD interface return query } @@ -187,16 +149,9 @@ func (region *TORegion) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap return errors.New("a region with " + err.Error()), eType } return err, eType -<<<<<<< HEAD } log.Errorf("received error: %++v from update execution", err) return tc.DBError, tc.SystemError -======= - } else { - log.Errorf("received error: %++v from update execution", err) - return tc.DBError, tc.SystemError - } ->>>>>>> updated to use the CRUD interface } defer resultRows.Close() @@ -214,14 +169,8 @@ func (region *TORegion) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap if rowsAffected != 1 { if rowsAffected < 1 { return errors.New("no region found with this id"), tc.DataMissingError -<<<<<<< HEAD } return fmt.Errorf("this update affected too many rows: %d", rowsAffected), tc.SystemError -======= - } else { - return fmt.Errorf("this update affected too many rows: %d", rowsAffected), tc.SystemError - } ->>>>>>> updated to use the CRUD interface } err = tx.Commit() if err != nil { @@ -232,23 +181,14 @@ func (region *TORegion) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap return nil, tc.NoError } -<<<<<<< HEAD //The TORegion implementation of the Creator interface //all implementations of Creator should use transactions and return the proper errorType -======= -//The TORegion implementation of the Inserter interface -//all implementations of Inserter should use transactions and return the proper errorType ->>>>>>> updated to use the CRUD interface //ParsePQUniqueConstraintError is used to determine if a region with conflicting values exists //if so, it will return an errorType of DataConflict and the type should be appended to the //generic error message returned //The insert sql returns the id and lastUpdated values of the newly inserted region and have //to be added to the struct -<<<<<<< HEAD func (region *TORegion) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) { -======= -func (region *TORegion) Insert(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErrorType) { ->>>>>>> updated to use the CRUD interface rollbackTransaction := true tx, err := db.Beginx() defer func() { @@ -273,16 +213,9 @@ func (region *TORegion) Insert(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap return errors.New("a region with " + err.Error()), eType } return err, eType -<<<<<<< HEAD } log.Errorf("received non pq error: %++v from create execution", err) return tc.DBError, tc.SystemError -======= - } else { - log.Errorf("received non pq error: %++v from create execution", err) - return tc.DBError, tc.SystemError - } ->>>>>>> updated to use the CRUD interface } defer resultRows.Close() @@ -300,12 +233,8 @@ func (region *TORegion) Insert(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap err = errors.New("no region was inserted, no id was returned") log.Errorln(err) return tc.DBError, tc.SystemError -<<<<<<< HEAD } if rowsAffected > 1 { -======= - } else if rowsAffected > 1 { ->>>>>>> updated to use the CRUD interface err = errors.New("too many ids returned from region insert") log.Errorln(err) return tc.DBError, tc.SystemError @@ -350,7 +279,6 @@ func (region *TORegion) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap if err != nil { return tc.DBError, tc.SystemError } -<<<<<<< HEAD if rowsAffected < 1 { return errors.New("no region with that id found"), tc.DataMissingError } @@ -358,15 +286,6 @@ func (region *TORegion) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap return fmt.Errorf("this create affected too many rows: %d", rowsAffected), tc.SystemError } -======= - if rowsAffected != 1 { - if rowsAffected < 1 { - return errors.New("no region with that id found"), tc.DataMissingError - } else { - return fmt.Errorf("this create affected too many rows: %d", rowsAffected), tc.SystemError - } - } ->>>>>>> updated to use the CRUD interface err = tx.Commit() if err != nil { log.Errorln("Could not commit transaction: ", err) @@ -379,10 +298,6 @@ func (region *TORegion) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.Ap func updateQuery() string { query := `UPDATE region SET -<<<<<<< HEAD -======= -description=:description, ->>>>>>> updated to use the CRUD interface division=:division, name=:name WHERE id=:id RETURNING last_updated` @@ -391,15 +306,8 @@ WHERE id=:id RETURNING last_updated` func insertQuery() string { query := `INSERT INTO region ( -<<<<<<< HEAD -division, -name) VALUES ( -======= -description, division, name) VALUES ( -:description, ->>>>>>> updated to use the CRUD interface :division, :name) RETURNING id,last_updated` return query -- To stop receiving notification emails like this one, please contact dang...@apache.org.