mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-07 13:31:37 +02:00
defaults tests
This commit is contained in:
parent
720786280c
commit
483290c5cd
@ -52,7 +52,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
if len(ctx.Config.Files) != 0 {
|
||||
return
|
||||
}
|
||||
files, err := findFiles(".")
|
||||
files, err := findFiles()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -60,17 +60,24 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func findFiles(path string) (files []string, err error) {
|
||||
all, err := ioutil.ReadDir(path)
|
||||
func findFiles() (files []string, err error) {
|
||||
all, err := ioutil.ReadDir(".")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, file := range all {
|
||||
for _, accepted := range defaultFiles {
|
||||
if strings.Contains(file.Name(), accepted) {
|
||||
files = append(files, file.Name())
|
||||
}
|
||||
if accept(file.Name()) {
|
||||
files = append(files, file.Name())
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func accept(file string) bool {
|
||||
for _, accepted := range defaultFiles {
|
||||
if strings.HasPrefix(file, accepted) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -24,4 +24,46 @@ func TestFillBasicData(t *testing.T) {
|
||||
assert.Contains(config.Build.Oses, "linux")
|
||||
assert.Contains(config.Build.Arches, "386")
|
||||
assert.Contains(config.Build.Arches, "amd64")
|
||||
assert.NotEmpty(
|
||||
config.Archive.Replacements,
|
||||
config.Archive.NameTemplate,
|
||||
config.Build.Ldflags,
|
||||
config.Files,
|
||||
)
|
||||
}
|
||||
|
||||
func TestFilesFilled(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var config = &config.ProjectConfig{
|
||||
Files: []string{
|
||||
"README.md",
|
||||
},
|
||||
}
|
||||
var ctx = &context.Context{
|
||||
Config: config,
|
||||
}
|
||||
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.Len(config.Files, 1)
|
||||
}
|
||||
|
||||
func TestAcceptFiles(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var files = []string{
|
||||
"LICENSE.md",
|
||||
"LICENSE.txt",
|
||||
"LICENSE",
|
||||
"LICENCE.txt",
|
||||
"LICENCE",
|
||||
"README",
|
||||
"README.md",
|
||||
"CHANGELOG.txt",
|
||||
"CHANGELOG.md",
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
assert.True(accept(file))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user