1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

Merge pull request #230 from client9/master

Add LoadReader function to prevent clients from having to deal with YAML
This commit is contained in:
Carlos Alexandro Becker 2017-05-11 00:16:39 -03:00 committed by GitHub
commit 563bae4682
2 changed files with 39 additions and 0 deletions

View File

@ -3,6 +3,7 @@
package config
import (
"io"
"io/ioutil"
yaml "gopkg.in/yaml.v1"
@ -116,3 +117,13 @@ func Load(file string) (config Project, err error) {
err = yaml.Unmarshal(data, &config)
return
}
// Load config via io.Reader
func LoadReader(fd io.Reader) (config Project, err error) {
data, err := ioutil.ReadAll(fd)
if err != nil {
return config, err
}
err = yaml.Unmarshal(data, &config)
return
}

28
config/config_test.go Normal file
View File

@ -0,0 +1,28 @@
package config
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRepo(t *testing.T) {
var assert = assert.New(t)
r := Repo{"goreleaser", "godownloader"}
assert.Equal("goreleaser/godownloader", r.String(), "not equal")
}
func TestLoadReader(t *testing.T) {
var conf = `
homepage: &homepage http://goreleaser.github.io
fpm:
homepage: *homepage
`
var assert = assert.New(t)
buf := strings.NewReader(conf)
prop, err := LoadReader(buf)
assert.Nil(err)
assert.Equal("http://goreleaser.github.io", prop.FPM.Homepage, "yaml did not load correctly")
}