1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/pkg/config/config_test.go

74 lines
1.6 KiB
Go
Raw Normal View History

2017-05-11 04:34:47 +02:00
package config
import (
2017-05-18 14:02:44 +02:00
"fmt"
2017-05-18 14:02:02 +02:00
"io/ioutil"
"os"
"path/filepath"
2017-05-11 04:34:47 +02:00
"strings"
2017-05-11 04:35:44 +02:00
"testing"
2017-05-11 04:34:47 +02:00
"github.com/stretchr/testify/require"
2017-05-11 04:34:47 +02:00
)
func TestRepo(t *testing.T) {
require.Equal(
t,
"goreleaser/godownloader",
Repo{Owner: "goreleaser", Name: "godownloader"}.String(),
)
}
func TestEmptyRepoNameAndOwner(t *testing.T) {
require.Empty(t, Repo{}.String())
2017-05-11 04:34:47 +02:00
}
func TestLoadReader(t *testing.T) {
2017-05-11 04:35:44 +02:00
var conf = `
nfpms:
- homepage: http://goreleaser.github.io
2017-05-11 04:34:47 +02:00
`
buf := strings.NewReader(conf)
prop, err := LoadReader(buf)
require.NoError(t, err)
require.Equal(t, "http://goreleaser.github.io", prop.NFPMs[0].Homepage, "yaml did not load correctly")
2017-05-11 04:34:47 +02:00
}
2017-05-18 14:02:02 +02: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{})
require.Error(t, err)
2017-05-18 14:02:02 +02:00
}
func TestFile(t *testing.T) {
f, err := ioutil.TempFile(os.TempDir(), "config")
require.NoError(t, err)
2017-05-18 14:02:02 +02:00
_, err = Load(filepath.Join(f.Name()))
require.NoError(t, err)
2017-05-18 14:02:02 +02:00
}
func TestFileNotFound(t *testing.T) {
_, err := Load("/nope/no-way.yml")
require.Error(t, err)
2017-05-18 14:02:02 +02:00
}
2017-07-08 17:05:57 +02:00
func TestInvalidFields(t *testing.T) {
_, err := Load("testdata/invalid_config.yml")
require.EqualError(t, err, "yaml: unmarshal errors:\n line 2: field invalid_yaml not found in type config.Build")
2017-07-08 17:05:57 +02:00
}
2017-08-04 03:25:25 +02:00
func TestInvalidYaml(t *testing.T) {
_, err := Load("testdata/invalid.yml")
require.EqualError(t, err, "yaml: line 1: did not find expected node content")
2017-08-04 03:25:25 +02:00
}
func TestConfigWithAnchors(t *testing.T) {
_, err := Load("testdata/anchor.yaml")
require.NoError(t, err)
}