You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	tests
This commit is contained in:
		| @@ -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 ( | ||||
| 	"testing" | ||||
| @@ -47,7 +47,7 @@ func create(name string, ctx *context.Context) error { | ||||
| 	var archive = archiveFor(file, ctx.Config.Archive.Format) | ||||
| 	defer func() { _ = archive.Close() }() | ||||
| 	for _, f := range ctx.Config.Files { | ||||
| 		if err := archive.Add(f, f); err != nil { | ||||
| 		if err = archive.Add(f, f); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -1,14 +1,13 @@ | ||||
| package defaults | ||||
|  | ||||
| import ( | ||||
| 	"os" | ||||
| 	"path" | ||||
| 	"path/filepath" | ||||
| 	"io/ioutil" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/goreleaser/releaser/context" | ||||
| ) | ||||
|  | ||||
| var filePatterns = []string{"LICENCE*", "LICENSE*", "README*", "CHANGELOG*"} | ||||
| var defaultFiles = []string{"LICENCE", "LICENSE", "README", "CHANGELOG"} | ||||
|  | ||||
| // Pipe for brew deployment | ||||
| type Pipe struct{} | ||||
| @@ -53,37 +52,25 @@ func (Pipe) Run(ctx *context.Context) (err error) { | ||||
| 	if len(ctx.Config.Files) != 0 { | ||||
| 		return | ||||
| 	} | ||||
| 	ctx.Config.Files = []string{} | ||||
| 	for _, pattern := range filePatterns { | ||||
| 		matches, err := globPath(pattern) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 	files, err := findFiles(".") | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	ctx.Config.Files = files | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func findFiles(path string) (files []string, err error) { | ||||
| 	all, err := ioutil.ReadDir(path) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	for _, file := range all { | ||||
| 		for _, accepted := range defaultFiles { | ||||
| 			if strings.Contains(file.Name(), accepted) { | ||||
| 				files = append(files, file.Name()) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		ctx.Config.Files = append(ctx.Config.Files, matches...) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func globPath(p string) (m []string, err error) { | ||||
| 	var cwd string | ||||
| 	var dirs []string | ||||
|  | ||||
| 	if cwd, err = os.Getwd(); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	fp := path.Join(cwd, p) | ||||
|  | ||||
| 	if dirs, err = filepath.Glob(fp); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// Normalise to avoid nested dirs in tarball | ||||
| 	for _, dir := range dirs { | ||||
| 		_, f := filepath.Split(dir) | ||||
| 		m = append(m, f) | ||||
| 	} | ||||
|  | ||||
| 	return | ||||
| } | ||||
|   | ||||
							
								
								
									
										27
									
								
								pipeline/defaults/defaults_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								pipeline/defaults/defaults_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -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") | ||||
| } | ||||
							
								
								
									
										28
									
								
								pipeline/valid/valid_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								pipeline/valid/valid_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -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