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

ocket8888 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 7691d16  Traffic Ops unit tests: TestGetMonitoringJSON sometimes fails 
(#4920)
7691d16 is described below

commit 7691d16c895d2380b81f8d149b91a9920f702ec4
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Wed Jul 29 21:20:42 2020 -0600

    Traffic Ops unit tests: TestGetMonitoringJSON sometimes fails (#4920)
    
    * Fixing GetMonitoringJson test
    
    * Code review fixes
    
    * Making interfaces into a sortable type
---
 .../monitoring/monitoring_test.go                  | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/traffic_ops/traffic_ops_golang/monitoring/monitoring_test.go 
b/traffic_ops/traffic_ops_golang/monitoring/monitoring_test.go
index c51278e..3f5ecb7 100644
--- a/traffic_ops/traffic_ops_golang/monitoring/monitoring_test.go
+++ b/traffic_ops/traffic_ops_golang/monitoring/monitoring_test.go
@@ -528,7 +528,12 @@ func TestGetMonitoringJSON(t *testing.T) {
        if err != nil {
                t.Errorf("GetMonitoringJSON expected: nil error, actual: %v", 
err)
        }
-
+       for _, cache := range resp.Response.TrafficServers {
+               cache.Interfaces = sortInterfaces(cache.Interfaces)
+       }
+       for _, cache := range sqlResp.TrafficServers {
+               cache.Interfaces = sortInterfaces(cache.Interfaces)
+       }
        resp.Response.TrafficServers = sortCaches(resp.Response.TrafficServers)
        sqlResp.TrafficServers = sortCaches(sqlResp.TrafficServers)
        resp.Response.TrafficMonitors = 
sortMonitors(resp.Response.TrafficMonitors)
@@ -606,6 +611,23 @@ func (s SortableCaches) Less(i, j int) bool {
        return s[i].HostName < s[j].HostName
 }
 
+type SortableInterfaces []tc.ServerInterfaceInfo
+
+func (s SortableInterfaces) Len() int {
+       return len(s)
+}
+func (s SortableInterfaces) Swap(i, j int) {
+       s[i], s[j] = s[j], s[i]
+}
+func (s SortableInterfaces) Less(i, j int) bool {
+       return s[i].Name < s[j].Name
+}
+
+func sortInterfaces(i []tc.ServerInterfaceInfo) []tc.ServerInterfaceInfo {
+       sort.Sort(SortableInterfaces(i))
+       return i
+}
+
 func sortCaches(p []Cache) []Cache {
        sort.Sort(SortableCaches(p))
        return p

Reply via email to