2016-12-28 22:16:02 -02:00
|
|
|
package config
|
2016-12-28 22:23:39 -02:00
|
|
|
|
|
|
|
import (
|
2016-12-30 17:31:06 +00:00
|
|
|
"os"
|
2016-12-30 12:03:43 -02:00
|
|
|
"testing"
|
2016-12-30 12:41:59 -02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2016-12-28 22:23:39 -02:00
|
|
|
)
|
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
func TestFillBasicData(t *testing.T) {
|
2016-12-28 22:23:39 -02:00
|
|
|
assert := assert.New(t)
|
2017-01-06 13:23:55 -02:00
|
|
|
config := ProjectConfig{}
|
|
|
|
config.fillBasicData()
|
2016-12-30 17:31:06 +00:00
|
|
|
|
2016-12-29 12:38:24 -02:00
|
|
|
assert.Equal("main.go", config.Build.Main)
|
2017-01-06 13:37:09 -02:00
|
|
|
assert.Equal("tar.gz", config.Archive.Format)
|
2016-12-28 22:23:39 -02:00
|
|
|
assert.Contains(config.Build.Oses, "darwin")
|
|
|
|
assert.Contains(config.Build.Oses, "linux")
|
|
|
|
assert.Contains(config.Build.Arches, "386")
|
|
|
|
assert.Contains(config.Build.Arches, "amd64")
|
|
|
|
}
|
2016-12-30 17:31:06 +00:00
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
func TestFillFilesMissingFiles(t *testing.T) {
|
2016-12-30 17:31:06 +00:00
|
|
|
assert := assert.New(t)
|
2016-12-31 10:03:25 -02:00
|
|
|
config := ProjectConfig{}
|
|
|
|
err := config.fillFiles()
|
2016-12-30 17:31:06 +00:00
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
assert.NoError(err)
|
2016-12-31 10:54:53 +00:00
|
|
|
assert.Equal([]string{}, config.Files)
|
2016-12-30 17:31:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
func TestFillFilesUSENMarkdown(t *testing.T) {
|
2017-01-02 10:51:24 -02:00
|
|
|
assertFiles(t, "./.test/1", []string{"LICENSE.md", "README.md"})
|
2016-12-31 10:54:53 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
func TestFillFilesRealENMarkdown(t *testing.T) {
|
2017-01-02 10:51:24 -02:00
|
|
|
assertFiles(t, "./.test/2", []string{"LICENCE.md", "README.md"})
|
2016-12-31 10:54:53 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
func TestFillFilesArbitratryENTXT(t *testing.T) {
|
2017-01-02 10:51:24 -02:00
|
|
|
assertFiles(t, "./.test/3", []string{"LICENCE.txt", "README.txt"})
|
2016-12-30 17:31:06 +00:00
|
|
|
}
|
2016-12-31 11:20:41 +00:00
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
func TestFillFilesArbitratryENNoSuffix(t *testing.T) {
|
2017-01-02 10:51:24 -02:00
|
|
|
assertFiles(t, "./.test/4", []string{"LICENCE"})
|
2016-12-31 10:03:25 -02:00
|
|
|
}
|
|
|
|
|
2016-12-31 14:05:14 -02:00
|
|
|
func TestFillFilesChangelog(t *testing.T) {
|
2017-01-02 10:51:24 -02:00
|
|
|
assertFiles(t, "./.test/5", []string{"CHANGELOG", "CHANGELOG.md"})
|
2016-12-31 14:05:14 -02:00
|
|
|
}
|
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
func TestValidadeMissingBinaryName(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
config := ProjectConfig{Repo: "asd/asd"}
|
2016-12-31 13:21:41 -02:00
|
|
|
assert.Error(config.validate())
|
2016-12-31 10:03:25 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidadeMissingRepo(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
config := ProjectConfig{BinaryName: "asd"}
|
2016-12-31 13:21:41 -02:00
|
|
|
assert.Error(config.validate())
|
2016-12-31 10:03:25 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidadeMinimalConfig(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2016-12-31 11:20:41 +00:00
|
|
|
|
2016-12-31 10:03:25 -02:00
|
|
|
config := ProjectConfig{BinaryName: "asd", Repo: "asd/asd"}
|
2016-12-31 13:21:41 -02:00
|
|
|
assert.NoError(config.validate())
|
2016-12-31 11:20:41 +00:00
|
|
|
}
|
2017-01-02 10:51:24 -02:00
|
|
|
|
|
|
|
func assertFiles(t *testing.T, dir string, files []string) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
cwd, _ := os.Getwd()
|
2017-01-02 13:20:33 -02:00
|
|
|
if err := os.Chdir(dir); err != nil {
|
2017-01-02 13:34:34 -02:00
|
|
|
panic(err)
|
2017-01-02 13:20:33 -02:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := os.Chdir(cwd); err != nil {
|
2017-01-02 13:34:34 -02:00
|
|
|
panic(err)
|
2017-01-02 13:20:33 -02:00
|
|
|
}
|
|
|
|
}()
|
2017-01-02 10:51:24 -02:00
|
|
|
|
|
|
|
config := ProjectConfig{}
|
|
|
|
err := config.fillFiles()
|
|
|
|
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(files, config.Files)
|
|
|
|
}
|