Skip to content

Commit

Permalink
Relaxing restriction on empty datasources
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
  • Loading branch information
hairyhenderson committed May 4, 2018
1 parent 381efb0 commit 6b28889
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions data/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,6 @@ func (d *Data) Datasource(alias string, args ...string) (interface{}, error) {
if err != nil {
return nil, errors.Wrapf(err, "Couldn't read datasource '%s'", alias)
}
if len(b) == 0 {
return nil, errors.Errorf("No value found for %s from datasource '%s'", args, alias)
}
s := string(b)
if source.Type == jsonMimetype {
return JSON(s), nil
Expand Down Expand Up @@ -411,6 +408,9 @@ func readVault(source *Source, args ...string) ([]byte, error) {
if err != nil {
return nil, err
}
if len(data) == 0 {
return nil, errors.Errorf("no value found for path %s", p)
}
source.Type = "application/json"

return data, nil
Expand Down
5 changes: 3 additions & 2 deletions data/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ func TestDatasource(t *testing.T) {
test("yml", "application/yaml", []byte("hello:\n cruel: world\n"))

d := setup("", "text/plain", nil)
_, err := d.Datasource("foo")
assert.Errorf(t, err, "No value found for")
actual, err := d.Datasource("foo")
assert.NoError(t, err)
assert.Equal(t, "", actual)
}

func TestDatasourceExists(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/datasources_vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *VaultDatasourcesSuite) TestTokenAuth(c *C) {
"VAULT_TOKEN=" + tok,
}
})
result.Assert(c, icmd.Expected{ExitCode: 1, Err: "No value found for [bar] from datasource 'vault'"})
result.Assert(c, icmd.Expected{ExitCode: 1, Err: "error calling ds: Couldn't read datasource 'vault': no value found for path /secret/bar"})

tokFile := fs.NewFile(c, "test-vault-token", fs.WithContent(tok))
defer tokFile.Remove()
Expand Down

0 comments on commit 6b28889

Please sign in to comment.