2017-05-10 19:34:47 -07:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2017-05-18 09:02:44 -03:00
|
|
|
"fmt"
|
2017-05-18 09:02:02 -03:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-05-10 19:34:47 -07:00
|
|
|
"strings"
|
2017-05-10 19:35:44 -07:00
|
|
|
"testing"
|
2017-05-10 19:34:47 -07:00
|
|
|
|
2017-05-10 19:35:44 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-05-10 19:34:47 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepo(t *testing.T) {
|
2017-10-15 17:46:21 -02:00
|
|
|
assert.Equal(
|
|
|
|
t,
|
|
|
|
"goreleaser/godownloader",
|
|
|
|
Repo{Owner: "goreleaser", Name: "godownloader"}.String(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmptyRepoNameAndOwner(t *testing.T) {
|
|
|
|
assert.Empty(t, Repo{}.String())
|
2017-05-10 19:34:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadReader(t *testing.T) {
|
2017-05-10 19:35:44 -07:00
|
|
|
var conf = `
|
2017-05-10 19:34:47 -07:00
|
|
|
fpm:
|
2017-07-08 12:05:57 -03:00
|
|
|
homepage: http://goreleaser.github.io
|
2017-05-10 19:34:47 -07:00
|
|
|
`
|
|
|
|
buf := strings.NewReader(conf)
|
|
|
|
prop, err := LoadReader(buf)
|
|
|
|
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "http://goreleaser.github.io", prop.FPM.Homepage, "yaml did not load correctly")
|
2017-05-10 19:34:47 -07:00
|
|
|
}
|
2017-05-18 09:02:02 -03:00
|
|
|
|
|
|
|
type errorReader struct{}
|
|
|
|
|
|
|
|
func (errorReader) Read(p []byte) (n int, err error) {
|
|
|
|
return 1, fmt.Errorf("error")
|
|
|
|
}
|
|
|
|
func TestLoadBadReader(t *testing.T) {
|
|
|
|
_, err := LoadReader(errorReader{})
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.Error(t, err)
|
2017-05-18 09:02:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFile(t *testing.T) {
|
|
|
|
f, err := ioutil.TempFile(os.TempDir(), "config")
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
2017-05-18 09:02:02 -03:00
|
|
|
_, err = Load(filepath.Join(f.Name()))
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.NoError(t, err)
|
2017-05-18 09:02:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFileNotFound(t *testing.T) {
|
|
|
|
_, err := Load("/nope/no-way.yml")
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.Error(t, err)
|
2017-05-18 09:02:02 -03:00
|
|
|
}
|
2017-07-08 12:05:57 -03:00
|
|
|
|
|
|
|
func TestInvalidFields(t *testing.T) {
|
|
|
|
_, err := Load("testdata/invalid_config.yml")
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.EqualError(t, err, "unknown fields in the config file: invalid_root, archive.invalid_archive, archive.format_overrides[0].invalid_archive_fmtoverrides, brew.invalid_brew, brew.github.invalid_brew_github, builds[0].invalid_builds, builds[0].hooks.invalid_builds_hooks, builds[0].ignored_builds[0].invalid_builds_ignore, fpm.invalid_fpm, release.invalid_release, release.github.invalid_release_github, build.invalid_build, builds.hooks.invalid_build_hook, builds.ignored_builds[0].invalid_build_ignore, snapshot.invalid_snapshot, docker[0].invalid_docker")
|
2017-07-08 12:05:57 -03:00
|
|
|
}
|
2017-08-03 22:25:25 -03:00
|
|
|
|
|
|
|
func TestInvalidYaml(t *testing.T) {
|
|
|
|
_, err := Load("testdata/invalid.yml")
|
2017-09-26 19:24:49 -03:00
|
|
|
assert.EqualError(t, err, "yaml: line 1: did not find expected node content")
|
2017-08-03 22:25:25 -03:00
|
|
|
}
|