data_source: support io.Reader

This commit is contained in:
ᴜɴᴋɴᴡᴏɴ
2020-03-07 14:13:37 +08:00
parent 32cf4f7e9c
commit fbbb7987e5
3 changed files with 7 additions and 9 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ test:
go test -v -cover -race
bench:
go test -v -cover -race -test.bench=. -test.benchmem
go test -v -cover -test.bench=. -test.benchmem
vet:
go vet
+2
View File
@@ -66,6 +66,8 @@ func parseDataSource(source interface{}) (dataSource, error) {
return sourceFile{s}, nil
case []byte:
return &sourceData{s}, nil
case io.Reader:
return &sourceReadCloser{ioutil.NopCloser(s)}, nil
case io.ReadCloser:
return &sourceReadCloser{s}, nil
default:
+4 -8
View File
@@ -52,15 +52,11 @@ var update = flag.Bool("update", false, "Update .golden files")
func TestLoad(t *testing.T) {
Convey("Load from good data sources", t, func() {
f, err := ini.Load([]byte(`
NAME = ini
VERSION = v1
IMPORT_PATH = gopkg.in/%(NAME)s.%(VERSION)s`),
f, err := ini.Load(
"testdata/minimal.ini",
ioutil.NopCloser(bytes.NewReader([]byte(`
[author]
NAME = Unknwon
`))),
[]byte("NAME = ini\nIMPORT_PATH = gopkg.in/%(NAME)s.%(VERSION)s"),
bytes.NewReader([]byte(`VERSION = v1`)),
ioutil.NopCloser(bytes.NewReader([]byte("[author]\nNAME = Unknwon"))),
)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)