mitchell852 closed pull request #2211: Fix TO Go CRConfig endpoints to wrap 
response obj
URL: https://github.com/apache/incubator-trafficcontrol/pull/2211
 
 
   

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/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go 
b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
index c7d705774..fe066b443 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice_test.go
@@ -20,12 +20,12 @@ package crconfig
  */
 
 import (
-       "strconv"
-       "strings"
+       "encoding/json"
        "math/rand"
        "reflect"
+       "strconv"
+       "strings"
        "testing"
-       "encoding/json"
 
        "github.com/apache/incubator-trafficcontrol/lib/go-tc"
 
@@ -46,7 +46,7 @@ func randMatchlistArr() []tc.MatchList {
        arr := []tc.MatchList{}
        for i := 0; i < num; i++ {
                arr = append(arr, tc.MatchList{
-                       Regex: *randStr(),
+                       Regex:     *randStr(),
                        MatchType: *randStr(),
                })
        }
@@ -59,7 +59,7 @@ func randMatchsetArr() []*tc.MatchSet {
        arr := []*tc.MatchSet{}
        for i := 0; i < num; i++ {
                arr = append(arr, &tc.MatchSet{
-                       Protocol: httpStr,
+                       Protocol:  httpStr,
                        MatchList: randMatchlistArr(),
                })
        }
@@ -82,44 +82,44 @@ func randDS() tc.CRConfigDeliveryService {
        geoProviderStr := GeoProviderMaxmindStr
        return tc.CRConfigDeliveryService{
                CoverageZoneOnly: false,
-               Dispersion:           &tc.CRConfigDispersion{
-                       Limit: 42,
+               Dispersion: &tc.CRConfigDispersion{
+                       Limit:    42,
                        Shuffled: true,
                },
                // Domains: []string{"foo"},
                GeoLocationProvider: &geoProviderStr,
                // MatchSets:            randMatchsetArr(),
-               MissLocation:         &tc.CRConfigLatitudeLongitudeShort{
+               MissLocation: &tc.CRConfigLatitudeLongitudeShort{
                        Lat: *randFloat64(),
                        Lon: *randFloat64(),
                },
-               Protocol:             &tc.CRConfigDeliveryServiceProtocol{
+               Protocol: &tc.CRConfigDeliveryServiceProtocol{
                        // AcceptHTTP: &truePtr,
-                       AcceptHTTPS: false,
+                       AcceptHTTPS:     false,
                        RedirectOnHTTPS: false,
                },
                RegionalGeoBlocking: &falseStrPtr,
-               ResponseHeaders: nil,
-               RequestHeaders: nil,
+               ResponseHeaders:     nil,
+               RequestHeaders:      nil,
                Soa: &tc.SOA{
-                       Admin:     &ttlAdmin,
-                       ExpireSeconds:     &ttlExpire,
-                       MinimumSeconds:     &ttlMinimum,
+                       Admin:          &ttlAdmin,
+                       ExpireSeconds:  &ttlExpire,
+                       MinimumSeconds: &ttlMinimum,
                        RefreshSeconds: &ttlRefresh,
-                       RetrySeconds: &ttlRetry,
+                       RetrySeconds:   &ttlRetry,
                },
                SSLEnabled: false,
-               TTL: ttl,
-               TTLs: &tc.CRConfigTTL {
-                       ASeconds: &ttlStr,
-                       AAAASeconds : &ttlStr,
-                       NSSeconds: &ttlNS,
-                       SOASeconds: &ttlSOA,
+               TTL:        ttl,
+               TTLs: &tc.CRConfigTTL{
+                       ASeconds:    &ttlStr,
+                       AAAASeconds: &ttlStr,
+                       NSSeconds:   &ttlNS,
+                       SOASeconds:  &ttlSOA,
                },
                // MaxDNSIPsForLocation: randInt(),
                IP6RoutingEnabled: randBool(),
-               RoutingName: randStr(),
-               BypassDestination:    map[string]*tc.CRConfigBypassDestination {
+               RoutingName:       randStr(),
+               BypassDestination: map[string]*tc.CRConfigBypassDestination{
                        "HTTP": &tc.CRConfigBypassDestination{
                                // IP: randStr(),
                                // IP6: randStr(),
@@ -130,13 +130,13 @@ func randDS() tc.CRConfigDeliveryService {
                        },
                },
                DeepCachingType: nil,
-               GeoEnabled: nil,
+               GeoEnabled:      nil,
                // GeoLimitRedirectURL: randStr(),
-               StaticDNSEntries:     []tc.StaticDNSEntry{
+               StaticDNSEntries: []tc.StaticDNSEntry{
                        tc.StaticDNSEntry{
-                               Name: *randStr(),
-                               TTL: *randInt(),
-                               Type: *randStr(),
+                               Name:  *randStr(),
+                               TTL:   *randInt(),
+                               Type:  *randStr(),
                                Value: *randStr(),
                        },
                },
@@ -212,7 +212,7 @@ func TestMakeDSes(t *testing.T) {
 func ExpectedGetServerProfileParams(expectedMakeDSes 
map[string]tc.CRConfigDeliveryService) map[string]map[string]string {
        expected := map[string]map[string]string{}
        for dsName, _ := range expectedMakeDSes {
-               expected[dsName] = map[string]string {
+               expected[dsName] = map[string]string{
                        "param0": "val0",
                        "param1": "val1",
                }
@@ -278,7 +278,7 @@ func ExpectedGetDSRegexesDomains(expectedDSParams 
map[string]string) (map[string
        }
 
        for dsName, _ := range expectedDSParams {
-               pattern := `.*\.`+dsName+`\..*`
+               pattern := `.*\.` + dsName + `\..*`
 
                matchsets[dsName][setnum] = &tc.MatchSet{}
                matchset := matchsets[dsName][setnum]
@@ -311,7 +311,6 @@ func TestGetDSRegexesDomains(t *testing.T) {
 
        cdn := "mycdn"
 
-
        expectedMakeDSes := ExpectedMakeDSes()
        expectedServerProfileParams := 
ExpectedGetServerProfileParams(expectedMakeDSes)
        expectedDSParams, err := getDSParams(expectedServerProfileParams)
@@ -334,14 +333,14 @@ func TestGetDSRegexesDomains(t *testing.T) {
        }
 
        if !reflect.DeepEqual(expectedMatchsets, actualMatchsets) {
-                       t.Errorf("getDSRegexesDomains expected: %+v, actual: 
%+v", expectedMatchsets, actualMatchsets)
+               t.Errorf("getDSRegexesDomains expected: %+v, actual: %+v", 
expectedMatchsets, actualMatchsets)
        }
        if !reflect.DeepEqual(expectedDomains, actualDomains) {
-                       t.Errorf("getDSRegexesDomains expected: %+v, actual: 
%+v", expectedDomains, actualDomains)
+               t.Errorf("getDSRegexesDomains expected: %+v, actual: %+v", 
expectedDomains, actualDomains)
        }
 }
 
-func ExpectedGetStaticDNSEntries(expectedMakeDSes 
map[string]tc.CRConfigDeliveryService) 
(map[tc.DeliveryServiceName][]tc.StaticDNSEntry) {
+func ExpectedGetStaticDNSEntries(expectedMakeDSes 
map[string]tc.CRConfigDeliveryService) 
map[tc.DeliveryServiceName][]tc.StaticDNSEntry {
        expected := map[tc.DeliveryServiceName][]tc.StaticDNSEntry{}
        for dsName, ds := range expectedMakeDSes {
                for _, entry := range ds.StaticDNSEntries {
@@ -355,7 +354,7 @@ func MockGetStaticDNSEntries(mock sqlmock.Sqlmock, expected 
map[tc.DeliveryServi
        rows := sqlmock.NewRows([]string{"ds", "name", "ttl", "value", "type"})
        for dsName, entries := range expected {
                for _, entry := range entries {
-                       rows = rows.AddRow(dsName, entry.Name, entry.TTL, 
entry.Value, entry.Type + "_RECORD")
+                       rows = rows.AddRow(dsName, entry.Name, entry.TTL, 
entry.Value, entry.Type+"_RECORD")
                }
        }
        mock.ExpectQuery("select").WithArgs(cdn).WillReturnRows(rows)
@@ -383,6 +382,6 @@ func TestGetStaticDNSEntries(t *testing.T) {
                t.Fatalf("getStaticDNSEntries len expected: %v, actual: %v", 
len(expected), len(actual))
        }
        if !reflect.DeepEqual(expected, actual) {
-                       t.Errorf("getDSRegexesDomains expected: %+v, actual: 
%+v", expected, actual)
+               t.Errorf("getDSRegexesDomains expected: %+v, actual: %+v", 
expected, actual)
        }
 }
diff --git a/traffic_ops/traffic_ops_golang/crconfig/handler.go 
b/traffic_ops/traffic_ops_golang/crconfig/handler.go
index 78b1fd185..3c11d5e4b 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/handler.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/handler.go
@@ -22,7 +22,6 @@ package crconfig
 import (
        "encoding/json"
        "errors"
-       "fmt"
        "net/http"
        "net/url"
        "strconv"
@@ -71,14 +70,17 @@ func Handler(db *sqlx.DB, cfg config.Config) 
http.HandlerFunc {
                        return
                }
 
-               respBts, err := json.Marshal(crConfig)
+               resp := struct {
+                       Response *tc.CRConfig `json:"response"`
+               }{crConfig}
+               respBts, err := json.Marshal(resp)
                if err != nil {
                        handleErrs(http.StatusInternalServerError, err)
                        return
                }
                log.Infof("CRConfig time to generate: %+v\n", time.Since(start))
                w.Header().Set("Content-Type", "application/json")
-               fmt.Fprintf(w, "%s", respBts)
+               w.Write(respBts)
        }
 }
 
@@ -107,7 +109,7 @@ func SnapshotGetHandler(db *sqlx.DB, cfg config.Config) 
http.HandlerFunc {
                        return
                }
                w.Header().Set("Content-Type", "application/json")
-               fmt.Fprintf(w, "%s", []byte(snapshot))
+               w.Write([]byte(`{"response":` + snapshot + `}`))
        }
 }
 
diff --git a/traffic_ops/traffic_ops_golang/crconfig/snapshot_test.go 
b/traffic_ops/traffic_ops_golang/crconfig/snapshot_test.go
index dc8cd22fb..e5732a1f9 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/snapshot_test.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/snapshot_test.go
@@ -20,10 +20,10 @@ package crconfig
  */
 
 import (
-       "reflect"
+       "database/sql/driver"
        "encoding/json"
+       "reflect"
        "testing"
-       "database/sql/driver"
        "time"
 
        "github.com/apache/incubator-trafficcontrol/lib/go-tc"
@@ -72,6 +72,7 @@ func TestGetSnapshot(t *testing.T) {
 }
 
 type AnyTime struct{}
+
 // Match satisfies sqlmock.Argument interface
 func (a AnyTime) Match(v driver.Value) bool {
        _, ok := v.(time.Time)
@@ -79,12 +80,12 @@ func (a AnyTime) Match(v driver.Value) bool {
 }
 
 type Any struct{}
+
 // Match satisfies sqlmock.Argument interface
 func (a Any) Match(v driver.Value) bool {
        return true
 }
 
-
 func MockSnapshot(mock sqlmock.Sqlmock, expected []byte, cdn string) {
        mock.ExpectExec("insert").WithArgs(cdn, expected, 
AnyTime{}).WillReturnResult(sqlmock.NewResult(1, 1))
 }
diff --git a/traffic_ops/traffic_ops_golang/crconfig/stats_test.go 
b/traffic_ops/traffic_ops_golang/crconfig/stats_test.go
index 166df4e5f..77b9f1f3b 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/stats_test.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/stats_test.go
@@ -21,19 +21,19 @@ package crconfig
 
 import (
        "reflect"
-       "time"
        "testing"
+       "time"
 
        "github.com/apache/incubator-trafficcontrol/lib/go-tc"
 )
 
 func ExpectedMakeStats() tc.CRConfigStats {
        return tc.CRConfigStats{
-               CDNName:         randStr(),
-               TMHost:          randStr(),
-               TMPath:          randStr(),
-               TMUser:          randStr(),
-               TMVersion:       randStr(),
+               CDNName:   randStr(),
+               TMHost:    randStr(),
+               TMPath:    randStr(),
+               TMUser:    randStr(),
+               TMVersion: randStr(),
        }
 }
 
@@ -46,7 +46,7 @@ func TestMakeStats(t *testing.T) {
        if !reflect.DeepEqual(expected, actual) {
                t.Errorf("makeStats expected: %+v, actual: %+v", expected, 
actual)
        }
-       if actual.DateUnixSeconds == nil ||  *actual.DateUnixSeconds < 
start.Unix() || *actual.DateUnixSeconds > end.Unix() {
+       if actual.DateUnixSeconds == nil || *actual.DateUnixSeconds < 
start.Unix() || *actual.DateUnixSeconds > end.Unix() {
                t.Errorf("makeStats DateUniSeconds expected: < %+v > %+v, 
actual: %+v", start.Unix(), end.Unix(), actual.DateUnixSeconds)
        }
 }


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to