mirror of
https://github.com/goreleaser/goreleaser.git
synced 2026-06-19 23:24:39 +02:00
tests
This commit is contained in:
15 files changed
+71
-120
No files matched your search
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
@@ -1,91 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFillBasicData(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
config := ProjectConfig{}
|
|
||||||
config.fillBasicData()
|
|
||||||
|
|
||||||
assert.Equal("main.go", config.Build.Main)
|
|
||||||
assert.Equal("tar.gz", config.Archive.Format)
|
|
||||||
assert.Contains(config.Build.Oses, "darwin")
|
|
||||||
assert.Contains(config.Build.Oses, "linux")
|
|
||||||
assert.Contains(config.Build.Arches, "386")
|
|
||||||
assert.Contains(config.Build.Arches, "amd64")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFillFilesMissingFiles(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
config := ProjectConfig{}
|
|
||||||
err := config.fillFiles()
|
|
||||||
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal([]string{}, config.Files)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFillFilesUSENMarkdown(t *testing.T) {
|
|
||||||
assertFiles(t, "./.test/1", []string{"LICENSE.md", "README.md"})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFillFilesRealENMarkdown(t *testing.T) {
|
|
||||||
assertFiles(t, "./.test/2", []string{"LICENCE.md", "README.md"})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFillFilesArbitratryENTXT(t *testing.T) {
|
|
||||||
assertFiles(t, "./.test/3", []string{"LICENCE.txt", "README.txt"})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFillFilesArbitratryENNoSuffix(t *testing.T) {
|
|
||||||
assertFiles(t, "./.test/4", []string{"LICENCE"})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFillFilesChangelog(t *testing.T) {
|
|
||||||
assertFiles(t, "./.test/5", []string{"CHANGELOG", "CHANGELOG.md"})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidadeMissingBinaryName(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
config := ProjectConfig{Repo: "asd/asd"}
|
|
||||||
assert.Error(config.validate())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidadeMissingRepo(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
config := ProjectConfig{BinaryName: "asd"}
|
|
||||||
assert.Error(config.validate())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidadeMinimalConfig(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
config := ProjectConfig{BinaryName: "asd", Repo: "asd/asd"}
|
|
||||||
assert.NoError(config.validate())
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertFiles(t *testing.T, dir string, files []string) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
cwd, _ := os.Getwd()
|
|
||||||
if err := os.Chdir(dir); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := os.Chdir(cwd); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
config := ProjectConfig{}
|
|
||||||
err := config.fillFiles()
|
|
||||||
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal(files, config.Files)
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package compress
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -47,7 +47,7 @@ func create(name string, ctx *context.Context) error {
|
|||||||
var archive = archiveFor(file, ctx.Config.Archive.Format)
|
var archive = archiveFor(file, ctx.Config.Archive.Format)
|
||||||
defer func() { _ = archive.Close() }()
|
defer func() { _ = archive.Close() }()
|
||||||
for _, f := range ctx.Config.Files {
|
for _, f := range ctx.Config.Files {
|
||||||
if err := archive.Add(f, f); err != nil {
|
if err = archive.Add(f, f); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package defaults
|
package defaults
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"io/ioutil"
|
||||||
"path"
|
"strings"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/goreleaser/releaser/context"
|
"github.com/goreleaser/releaser/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
var filePatterns = []string{"LICENCE*", "LICENSE*", "README*", "CHANGELOG*"}
|
var defaultFiles = []string{"LICENCE", "LICENSE", "README", "CHANGELOG"}
|
||||||
|
|
||||||
// Pipe for brew deployment
|
// Pipe for brew deployment
|
||||||
type Pipe struct{}
|
type Pipe struct{}
|
||||||
@@ -53,37 +52,25 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
|||||||
if len(ctx.Config.Files) != 0 {
|
if len(ctx.Config.Files) != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Config.Files = []string{}
|
files, err := findFiles(".")
|
||||||
for _, pattern := range filePatterns {
|
|
||||||
matches, err := globPath(pattern)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Config.Files = append(ctx.Config.Files, matches...)
|
|
||||||
}
|
}
|
||||||
|
ctx.Config.Files = files
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func globPath(p string) (m []string, err error) {
|
func findFiles(path string) (files []string, err error) {
|
||||||
var cwd string
|
all, err := ioutil.ReadDir(path)
|
||||||
var dirs []string
|
if err != nil {
|
||||||
|
|
||||||
if cwd, err = os.Getwd(); err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for _, file := range all {
|
||||||
fp := path.Join(cwd, p)
|
for _, accepted := range defaultFiles {
|
||||||
|
if strings.Contains(file.Name(), accepted) {
|
||||||
if dirs, err = filepath.Glob(fp); err != nil {
|
files = append(files, file.Name())
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalise to avoid nested dirs in tarball
|
|
||||||
for _, dir := range dirs {
|
|
||||||
_, f := filepath.Split(dir)
|
|
||||||
m = append(m, f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package defaults
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goreleaser/releaser/config"
|
||||||
|
"github.com/goreleaser/releaser/context"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFillBasicData(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var config = &config.ProjectConfig{}
|
||||||
|
var ctx = &context.Context{
|
||||||
|
Config: config,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(Pipe{}.Run(ctx))
|
||||||
|
|
||||||
|
assert.Equal("main.go", config.Build.Main)
|
||||||
|
assert.Equal("tar.gz", config.Archive.Format)
|
||||||
|
assert.Contains(config.Build.Oses, "darwin")
|
||||||
|
assert.Contains(config.Build.Oses, "linux")
|
||||||
|
assert.Contains(config.Build.Arches, "386")
|
||||||
|
assert.Contains(config.Build.Arches, "amd64")
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package valid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidadeMissingBinaryName(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
config := ProjectConfig{Repo: "asd/asd"}
|
||||||
|
assert.Error(config.validate())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidadeMissingRepo(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
config := ProjectConfig{BinaryName: "asd"}
|
||||||
|
assert.Error(config.validate())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidadeMinimalConfig(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
config := ProjectConfig{BinaryName: "asd", Repo: "asd/asd"}
|
||||||
|
assert.NoError(config.validate())
|
||||||
|
}
|
||||||
Reference in new issue
Block a user