mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
defaults tests
This commit is contained in:
parent
0359e02b8d
commit
4fa83104d8
@ -41,6 +41,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
if ctx.Config.Brew.Install == "" {
|
||||
var installs []string
|
||||
for _, build := range ctx.Config.Builds {
|
||||
// TODO: check for OSX builds only
|
||||
installs = append(
|
||||
installs,
|
||||
fmt.Sprintf(`bin.install "%s"`, build.Binary),
|
||||
@ -66,31 +67,37 @@ func setReleaseDefaults(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func setBuildDefaults(ctx *context.Context) {
|
||||
var builds []config.Build
|
||||
log.WithField("builds", ctx.Config.Builds).Debug("builds cleaned")
|
||||
for _, build := range ctx.Config.Builds {
|
||||
if build.Binary == "" {
|
||||
build.Binary = ctx.Config.Release.GitHub.Name
|
||||
}
|
||||
if build.Main == "" {
|
||||
build.Main = "."
|
||||
}
|
||||
if len(build.Goos) == 0 {
|
||||
build.Goos = []string{"linux", "darwin"}
|
||||
}
|
||||
if len(build.Goarch) == 0 {
|
||||
build.Goarch = []string{"amd64", "386"}
|
||||
}
|
||||
if len(build.Goarm) == 0 {
|
||||
build.Goarm = []string{"6"}
|
||||
}
|
||||
if build.Ldflags == "" {
|
||||
build.Ldflags = "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
|
||||
}
|
||||
builds = append(builds, build)
|
||||
for i, build := range ctx.Config.Builds {
|
||||
ctx.Config.Builds[i] = buildWithDefaults(ctx, build)
|
||||
}
|
||||
ctx.Config.Builds = builds
|
||||
log.WithField("builds", ctx.Config.Builds).Debug("set")
|
||||
if len(ctx.Config.Builds) == 0 {
|
||||
ctx.Config.Builds = []config.Build{
|
||||
buildWithDefaults(ctx, config.Build{}),
|
||||
}
|
||||
}
|
||||
log.WithField("builds", ctx.Config.Builds).Info("set")
|
||||
}
|
||||
|
||||
func buildWithDefaults(ctx *context.Context, build config.Build) config.Build {
|
||||
if build.Binary == "" {
|
||||
build.Binary = ctx.Config.Release.GitHub.Name
|
||||
}
|
||||
if build.Main == "" {
|
||||
build.Main = "."
|
||||
}
|
||||
if len(build.Goos) == 0 {
|
||||
build.Goos = []string{"linux", "darwin"}
|
||||
}
|
||||
if len(build.Goarch) == 0 {
|
||||
build.Goarch = []string{"amd64", "386"}
|
||||
}
|
||||
if len(build.Goarm) == 0 {
|
||||
build.Goarm = []string{"6"}
|
||||
}
|
||||
if build.Ldflags == "" {
|
||||
build.Ldflags = "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
|
||||
}
|
||||
return build
|
||||
}
|
||||
|
||||
func setArchiveDefaults(ctx *context.Context) error {
|
||||
|
@ -15,33 +15,32 @@ func TestDescription(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFillBasicData(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
|
||||
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||
assert.Equal("goreleaser", ctx.Config.Release.GitHub.Name)
|
||||
assert.Equal("goreleaser", ctx.Config.Build.Binary)
|
||||
assert.Equal(".", ctx.Config.Build.Main)
|
||||
assert.NotEmpty(ctx.Config.Builds)
|
||||
assert.Equal("goreleaser", ctx.Config.Builds[0].Binary)
|
||||
assert.Equal(".", ctx.Config.Builds[0].Main)
|
||||
assert.Contains(ctx.Config.Builds[0].Goos, "darwin")
|
||||
assert.Contains(ctx.Config.Builds[0].Goos, "linux")
|
||||
assert.Contains(ctx.Config.Builds[0].Goarch, "386")
|
||||
assert.Contains(ctx.Config.Builds[0].Goarch, "amd64")
|
||||
assert.Equal("tar.gz", ctx.Config.Archive.Format)
|
||||
assert.Contains(ctx.Config.Build.Goos, "darwin")
|
||||
assert.Contains(ctx.Config.Build.Goos, "linux")
|
||||
assert.Contains(ctx.Config.Build.Goarch, "386")
|
||||
assert.Contains(ctx.Config.Build.Goarch, "amd64")
|
||||
assert.Contains(ctx.Config.Brew.Install, "bin.install \"goreleaser\"")
|
||||
assert.NotEmpty(
|
||||
ctx.Config.Archive.NameTemplate,
|
||||
ctx.Config.Build.Ldflags,
|
||||
ctx.Config.Builds[0].Ldflags,
|
||||
ctx.Config.Archive.Files,
|
||||
)
|
||||
}
|
||||
|
||||
func TestFillPartial(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var assert = assert.New(t)
|
||||
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
@ -56,6 +55,9 @@ func TestFillPartial(t *testing.T) {
|
||||
"glob/*",
|
||||
},
|
||||
},
|
||||
Builds: []config.Build{
|
||||
{Binary: "testreleaser"},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
|
@ -1,8 +1,10 @@
|
||||
package defaults
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -24,3 +26,65 @@ func TestExtractReporFromHttpsURL(t *testing.T) {
|
||||
repo := extractRepoFromURL("https://github.com/goreleaser/goreleaser.git")
|
||||
assert.Equal("goreleaser/goreleaser", repo.String())
|
||||
}
|
||||
|
||||
func Test_remoteRepo(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
wantResult config.Repo
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotResult, err := remoteRepo()
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("remoteRepo() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(gotResult, tt.wantResult) {
|
||||
t.Errorf("remoteRepo() = %v, want %v", gotResult, tt.wantResult)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_extractRepoFromURL(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want config.Repo
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := extractRepoFromURL(tt.args.s); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("extractRepoFromURL() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_toRepo(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want config.Repo
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := toRepo(tt.args.s); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("toRepo() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user