2019-07-24 22:14:03 +02:00
|
|
|
package config_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
2019-08-13 23:01:38 +02:00
|
|
|
|
|
|
|
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-07-24 22:14:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestReadCacheNotFound(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
_, err := config.Read("notfound/dir")
|
|
|
|
|
assert.Errorf(t, err, "Read non exsiting file")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestReadCacheInvalidContent(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "prefix")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
|
|
completePath := path.Join(path.Dir(dir), ".release.yml")
|
|
|
|
|
brokenContent := []byte("hello broken\ngo: lang\n")
|
|
|
|
|
err = ioutil.WriteFile(completePath, brokenContent, 0644)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
_, readError := config.Read(completePath)
|
|
|
|
|
assert.Errorf(t, readError, "Should give error, when broken content")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestWriteAndReadCache(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "prefix")
|
|
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
2020-01-05 18:41:44 +01:00
|
|
|
os.Setenv("TEST_CONFIG", "value")
|
|
|
|
|
defer os.Unsetenv("TEST_CONFIG")
|
|
|
|
|
|
2019-07-24 22:14:03 +02:00
|
|
|
completePath := path.Join(path.Dir(dir), ".release.yml")
|
|
|
|
|
content := []byte(`
|
|
|
|
|
commitFormat: angular
|
|
|
|
|
title: "go-semantic-release release"
|
|
|
|
|
branch:
|
|
|
|
|
master: release
|
|
|
|
|
rc: rc
|
|
|
|
|
beta: beta
|
|
|
|
|
alpha: alpha
|
|
|
|
|
add_git_releases: alpha
|
|
|
|
|
changelog:
|
|
|
|
|
printAll: false
|
2020-01-05 18:41:44 +01:00
|
|
|
template: ""
|
|
|
|
|
templatePath: '${TEST_CONFIG}'
|
2019-07-24 22:14:03 +02:00
|
|
|
release: 'github'
|
2020-01-05 18:41:44 +01:00
|
|
|
hooks:
|
|
|
|
|
preRelease:
|
|
|
|
|
- "Test hook ${RELEASE_VERSION}"
|
2019-07-24 22:14:03 +02:00
|
|
|
assets:
|
|
|
|
|
- name: ./build/go-semantic-release
|
|
|
|
|
compress: false
|
|
|
|
|
github:
|
|
|
|
|
repo: "go-semantic-release"
|
|
|
|
|
user: "nightapes"
|
|
|
|
|
customUrl: ""
|
|
|
|
|
`)
|
|
|
|
|
err = ioutil.WriteFile(completePath, content, 0644)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
result, readError := config.Read(completePath)
|
|
|
|
|
assert.NoErrorf(t, readError, "Should read file")
|
|
|
|
|
|
|
|
|
|
assert.EqualValues(t, &config.ReleaseConfig{
|
|
|
|
|
CommitFormat: "angular",
|
|
|
|
|
Branch: map[string]string{"add_git_releases": "alpha", "alpha": "alpha", "beta": "beta", "master": "release", "rc": "rc"},
|
|
|
|
|
Changelog: config.ChangelogConfig{
|
2019-09-22 15:50:12 +02:00
|
|
|
PrintAll: false,
|
|
|
|
|
TemplateTitle: "",
|
2020-01-05 18:41:44 +01:00
|
|
|
TemplatePath: "value"},
|
2019-07-24 22:14:03 +02:00
|
|
|
Release: "github",
|
|
|
|
|
GitHubProvider: config.GitHubProvider{
|
|
|
|
|
Repo: "go-semantic-release",
|
|
|
|
|
User: "nightapes",
|
|
|
|
|
CustomURL: "",
|
|
|
|
|
AccessToken: ""},
|
2020-01-05 18:41:44 +01:00
|
|
|
Hooks: config.Hooks{
|
|
|
|
|
PreRelease: []string{
|
|
|
|
|
"Test hook ${RELEASE_VERSION}",
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-07-24 22:14:03 +02:00
|
|
|
Assets: []config.Asset{
|
2021-01-21 21:41:14 +01:00
|
|
|
{
|
2019-07-24 22:14:03 +02:00
|
|
|
Name: "./build/go-semantic-release",
|
|
|
|
|
Compress: false}},
|
|
|
|
|
ReleaseTitle: "go-semantic-release release",
|
|
|
|
|
IsPreRelease: false,
|
2021-02-22 11:45:32 +01:00
|
|
|
Analyzer: config.AnalyzerConfig{TokenSeparators: []string{}},
|
2019-07-24 22:14:03 +02:00
|
|
|
}, result)
|
|
|
|
|
|
|
|
|
|
}
|