You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2018/08/06 15:48:34 UTC
[trafficcontrol] 05/08: Update CRConfig unit test for edgeLocations
localizationMethods
This is an automated email from the ASF dual-hosted git repository.
dewrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 96a7e2365d48146849355bcc7fb495332c86e575
Author: Rawlin Peters <ra...@comcast.com>
AuthorDate: Tue Jul 17 13:06:34 2018 -0600
Update CRConfig unit test for edgeLocations localizationMethods
---
lib/go-tc/enum.go | 2 +-
.../traffic_ops_golang/crconfig/edgelocations.go | 2 +-
.../crconfig/edgelocations_test.go | 30 +++++++++++++++++-----
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/lib/go-tc/enum.go b/lib/go-tc/enum.go
index 7a55301..4ab943f 100644
--- a/lib/go-tc/enum.go
+++ b/lib/go-tc/enum.go
@@ -261,7 +261,7 @@ func (m *LocalizationMethod) Scan(value interface{}) error {
}
return nil
default:
- return fmt.Errorf("failed to scan LocalizationMethod, unknown input type: %T", value)
+ return fmt.Errorf("failed to scan LocalizationMethod, unsupported input type: %T", value)
}
}
diff --git a/traffic_ops/traffic_ops_golang/crconfig/edgelocations.go b/traffic_ops/traffic_ops_golang/crconfig/edgelocations.go
index 86d8038..64c216b 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/edgelocations.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/edgelocations.go
@@ -34,7 +34,7 @@ func makeLocations(cdn string, db *sql.DB) (map[string]tc.CRConfigLatitudeLongit
// TODO test whether it's faster to do a single query, joining lat/lon into servers
q := `
select cg.name, cg.id, t.name as type, co.latitude, co.longitude, cg.fallback_to_closest,
-(SELECT array_agg(method::text) FROM cachegroup_localization_method WHERE cachegroup = cg.id)
+(SELECT array_agg(method::text) as localization_methods FROM cachegroup_localization_method WHERE cachegroup = cg.id)
from cachegroup as cg
left join coordinate as co on co.id = cg.coordinate
inner join server as s on s.cachegroup = cg.id
diff --git a/traffic_ops/traffic_ops_golang/crconfig/edgelocations_test.go b/traffic_ops/traffic_ops_golang/crconfig/edgelocations_test.go
index b0cd674..3465fb7 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/edgelocations_test.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/edgelocations_test.go
@@ -30,22 +30,38 @@ import (
func ExpectedMakeLocations() (map[string]tc.CRConfigLatitudeLongitude, map[string]tc.CRConfigLatitudeLongitude) {
return map[string]tc.CRConfigLatitudeLongitude{
- "cache0": tc.CRConfigLatitudeLongitude{Lat: *randFloat64(), Lon: *randFloat64()},
- "cache1": tc.CRConfigLatitudeLongitude{Lat: *randFloat64(), Lon: *randFloat64()},
+ "cache0": tc.CRConfigLatitudeLongitude{
+ Lat: *randFloat64(),
+ Lon: *randFloat64(),
+ LocalizationMethods: []tc.LocalizationMethod{tc.LocalizationMethodCZ},
+ },
+ "cache1": tc.CRConfigLatitudeLongitude{
+ Lat: *randFloat64(),
+ Lon: *randFloat64(),
+ LocalizationMethods: []tc.LocalizationMethod{tc.LocalizationMethodCZ},
+ },
},
map[string]tc.CRConfigLatitudeLongitude{
- "router0": tc.CRConfigLatitudeLongitude{Lat: *randFloat64(), Lon: *randFloat64()},
- "router1": tc.CRConfigLatitudeLongitude{Lat: *randFloat64(), Lon: *randFloat64()},
+ "router0": tc.CRConfigLatitudeLongitude{
+ Lat: *randFloat64(),
+ Lon: *randFloat64(),
+ LocalizationMethods: []tc.LocalizationMethod{tc.LocalizationMethodGeo, tc.LocalizationMethodCZ, tc.LocalizationMethodDeepCZ},
+ },
+ "router1": tc.CRConfigLatitudeLongitude{
+ Lat: *randFloat64(),
+ Lon: *randFloat64(),
+ LocalizationMethods: []tc.LocalizationMethod{tc.LocalizationMethodGeo, tc.LocalizationMethodCZ, tc.LocalizationMethodDeepCZ},
+ },
}
}
func MockMakeLocations(mock sqlmock.Sqlmock, expectedEdgeLocs map[string]tc.CRConfigLatitudeLongitude, expectedRouterLocs map[string]tc.CRConfigLatitudeLongitude, cdn string) {
- rows := sqlmock.NewRows([]string{"name", "id", "type", "latitude", "longitude", "fallback_to_closest"})
+ rows := sqlmock.NewRows([]string{"name", "id", "type", "latitude", "longitude", "fallback_to_closest", "localization_methods"})
for s, l := range expectedEdgeLocs {
- rows = rows.AddRow(s, 1, EdgeTypePrefix, l.Lat, l.Lon, false)
+ rows = rows.AddRow(s, 1, EdgeTypePrefix, l.Lat, l.Lon, false, []byte("{CZ}"))
}
for s, l := range expectedRouterLocs {
- rows = rows.AddRow(s, 1, RouterTypeName, l.Lat, l.Lon, false)
+ rows = rows.AddRow(s, 1, RouterTypeName, l.Lat, l.Lon, false, nil)
}
mock.ExpectQuery("select").WithArgs(cdn).WillReturnRows(rows)