tpl/data: Allows user-defined HTTP headers with getJSON and getCSV

Updates #5617
This commit is contained in:
Paul Chamberlain
2021-04-26 16:41:37 -04:00
committed by Bjørn Erik Pedersen
parent 06d295427f
commit 150d75738b
2 changed files with 49 additions and 4 deletions

View File

@@ -119,6 +119,20 @@ func TestGetCSV(t *testing.T) {
c.Assert(got, qt.Not(qt.IsNil), msg)
c.Assert(got, qt.DeepEquals, test.expect, msg)
// Test user-defined headers as well
gotHeader, _ := ns.GetCSV(test.sep, test.url, map[string]interface{}{"Accept-Charset": "utf-8", "Max-Forwards": "10"})
if _, ok := test.expect.(bool); ok {
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 1)
// c.Assert(err, msg, qt.Not(qt.IsNil))
c.Assert(got, qt.IsNil)
continue
}
c.Assert(err, qt.IsNil, msg)
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 0)
c.Assert(gotHeader, qt.Not(qt.IsNil), msg)
c.Assert(gotHeader, qt.DeepEquals, test.expect, msg)
}
}
@@ -206,6 +220,19 @@ func TestGetJSON(t *testing.T) {
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 0, msg)
c.Assert(got, qt.Not(qt.IsNil), msg)
c.Assert(got, qt.DeepEquals, test.expect)
// Test user-defined headers as well
gotHeader, _ := ns.GetJSON(test.url, map[string]interface{}{"Accept-Charset": "utf-8", "Max-Forwards": "10"})
if _, ok := test.expect.(bool); ok {
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 1)
// c.Assert(err, msg, qt.Not(qt.IsNil))
continue
}
c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 0, msg)
c.Assert(gotHeader, qt.Not(qt.IsNil), msg)
c.Assert(gotHeader, qt.DeepEquals, test.expect)
}
}