Skip to content

Commit

Permalink
fixup! Allowing datasources to be defined dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
hairyhenderson committed Jul 13, 2018
1 parent 092f707 commit fdf0d2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (d *Data) Datasource(alias string, args ...string) (interface{}, error) {
if err != nil {
return nil, err
}
source.Header = d.extraHeaders[alias]
d.Sources[alias] = source
}
b, err := d.ReadSource(source, args...)
Expand Down
13 changes: 13 additions & 0 deletions data/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ func TestHTTPFileWithHeaders(t *testing.T) {
actual, err := data.Datasource("foo")
assert.NoError(t, err)
assert.Equal(t, marshalObj(expected, json.Marshal), marshalObj(actual, json.Marshal))

expected = http.Header{
"Accept-Encoding": {"test"},
"Foo": {"bar", "baz"},
"User-Agent": {"Go-http-client/1.1"},
}
data = &Data{
Sources: sources,
extraHeaders: map[string]http.Header{server.URL: expected},
}
actual, err = data.Datasource(server.URL)
assert.NoError(t, err)
assert.Equal(t, marshalObj(expected, json.Marshal), marshalObj(actual, json.Marshal))
}

func TestParseHeaderArgs(t *testing.T) {
Expand Down

0 comments on commit fdf0d2c

Please sign in to comment.