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

rawlin pushed a commit to branch 4.0.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/4.0.x by this push:
     new 1523be3  Fix omitempty issue for ATS config metadata generation 
(#4306) (#4313)
1523be3 is described below

commit 1523be3d2238243f0f2ca3ab9d3d93c69b9ae3c9
Author: Rawlin Peters <[email protected]>
AuthorDate: Wed Jan 22 10:06:56 2020 -0700

    Fix omitempty issue for ATS config metadata generation (#4306) (#4313)
    
    If empty, the 'url' and 'apiUri' fields should be omitted from the
    marshalled JSON, which is how Perl handled it.
    
    (cherry picked from commit 5f3c3f26f1fe8309bf83e8397937ffc442cf1b21)
---
 lib/go-atscfg/meta_test.go | 31 +++++++++++++++++++++++++++++++
 lib/go-tc/ats.go           |  4 ++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/lib/go-atscfg/meta_test.go b/lib/go-atscfg/meta_test.go
index 5317220..dbd7b52 100644
--- a/lib/go-atscfg/meta_test.go
+++ b/lib/go-atscfg/meta_test.go
@@ -109,6 +109,11 @@ func TestMakeMetaConfig(t *testing.T) {
                        FileNameOnDisk: "custom.config",
                        Location:       "/my/location/",
                },
+               "external.config": ConfigProfileParams{
+                       FileNameOnDisk: "external.config",
+                       Location:       "/my/location/",
+                       URL:            "http://myurl/remap.config";,
+               },
        }
        uriSignedDSes := []tc.DeliveryServiceName{"mydsname"}
        dses := map[tc.DeliveryServiceName]struct{}{"mydsname": {}}
@@ -233,6 +238,14 @@ func TestMakeMetaConfig(t *testing.T) {
                                t.Errorf("expected scope '%v', actual '%v'", 
expected, cf.Scope)
                        }
                },
+               "external.config": func(cf tc.ATSConfigMetaDataConfigFile) {
+                       if expected := "/my/location/"; cf.Location != expected 
{
+                               t.Errorf("expected location '%v', actual '%v'", 
expected, cf.Location)
+                       }
+                       if expected := 
string(tc.ATSConfigMetaDataConfigFileScopeCDNs); cf.Scope != expected {
+                               t.Errorf("expected scope '%v', actual '%v'", 
expected, cf.Scope)
+                       }
+               },
        }
 
        for _, cfgFile := range cfg.ConfigFiles {
@@ -262,4 +275,22 @@ func TestMakeMetaConfig(t *testing.T) {
        if strings.Contains(txt, "nonexistentds") {
                t.Errorf("expected location parameters for nonexistent delivery 
services to not be added to config, actual '%v'", txt)
        }
+
+       // check for expected apiUri vs url keys (if values are empty strings, 
they should be omitted from the json)
+       m := map[string]interface{}{}
+       if err := json.Unmarshal([]byte(txt), &m); err != nil {
+               t.Fatalf("MakeMetaConfig returned invalid JSON: " + err.Error())
+       }
+       cfl := m["configFiles"].([]interface{})
+       for _, cf := range cfl {
+               c := cf.(map[string]interface{})
+               if c["fnameOnDisk"] == "external.config" {
+                       if _, exists := c["apiUri"]; exists {
+                               t.Errorf("expected: apiUri field to be omitted 
for external.config, actual: present")
+                       }
+                       if _, exists := c["url"]; !exists {
+                               t.Errorf("expected: url field to be present for 
external.config, actual: omitted")
+                       }
+               }
+       }
 }
diff --git a/lib/go-tc/ats.go b/lib/go-tc/ats.go
index 106c048..c7af337 100644
--- a/lib/go-tc/ats.go
+++ b/lib/go-tc/ats.go
@@ -44,8 +44,8 @@ type ATSConfigMetaDataInfo struct {
 type ATSConfigMetaDataConfigFile struct {
        FileNameOnDisk string `json:"fnameOnDisk"`
        Location       string `json:"location"`
-       APIURI         string `json:"apiUri, omitempty"`
-       URL            string `json:"url, omitempty"`
+       APIURI         string `json:"apiUri,omitempty"`
+       URL            string `json:"url,omitempty"`
        Scope          string `json:"scope"`
 }
 

Reply via email to