summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2021-01-17 15:46:57 -0500
committerDave Henderson <dhenderson@gmail.com>2021-01-17 16:48:48 -0500
commitd6c72218477357bc855f700ca6134d40cd96adf0 (patch)
tree0eb5a3f593fde1aafac6988aafe5ffbe197c2568 /data
parent5835d0d688525716be902297193f78227994f5bf (diff)
Inject stdin/out/err instead of always using os.Stdin/out/err
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'data')
-rw-r--r--data/datasource.go8
-rw-r--r--data/datasource_stdin.go8
2 files changed, 8 insertions, 8 deletions
diff --git a/data/datasource.go b/data/datasource.go
index 147ba013..0f2c44fa 100644
--- a/data/datasource.go
+++ b/data/datasource.go
@@ -3,7 +3,6 @@ package data
import (
"context"
"fmt"
- "io"
"mime"
"net/http"
"net/url"
@@ -19,9 +18,6 @@ import (
"github.com/hairyhenderson/gomplate/v3/vault"
)
-// stdin - for overriding in tests
-var stdin io.Reader
-
func regExtension(ext, typ string) {
err := mime.AddExtensionType(ext, typ)
if err != nil {
@@ -114,6 +110,10 @@ func NewData(datasourceArgs, headerArgs []string) (*Data, error) {
// FromConfig - internal use only!
func FromConfig(ctx context.Context, cfg *config.Config) *Data {
+ // XXX: This is temporary, and will be replaced with something a bit cleaner
+ // when datasources are refactored
+ stdin = cfg.Stdin
+
sources := map[string]*Source{}
for alias, d := range cfg.DataSources {
sources[alias] = &Source{
diff --git a/data/datasource_stdin.go b/data/datasource_stdin.go
index f23905d2..8216573b 100644
--- a/data/datasource_stdin.go
+++ b/data/datasource_stdin.go
@@ -1,16 +1,16 @@
package data
import (
+ "io"
"io/ioutil"
- "os"
"github.com/pkg/errors"
)
+// stdin - for overriding in tests
+var stdin io.Reader
+
func readStdin(source *Source, args ...string) ([]byte, error) {
- if stdin == nil {
- stdin = os.Stdin
- }
b, err := ioutil.ReadAll(stdin)
if err != nil {
return nil, errors.Wrapf(err, "Can't read %s", stdin)