1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

more test

This commit is contained in:
Carlos Alexandro Becker 2017-03-25 21:29:38 -03:00
parent 5bb80dd0a8
commit 7610138016
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
8 changed files with 62 additions and 5 deletions

View File

@ -75,6 +75,9 @@ type Project struct {
Build Build
Archive Archive
FPM FPM `yaml:"fpm"`
// test only property:
TargetFolder string `yaml:"-"`
}
// Load config file

View File

@ -39,7 +39,7 @@ type Archive interface {
}
func create(name string, ctx *context.Context) error {
folder := filepath.Join("dist", name)
folder := filepath.Join(ctx.Config.TargetFolder, name)
file, err := os.Create(folder + "." + ctx.Config.Archive.Format)
log.Println("Creating", file.Name())
if err != nil {

View File

@ -186,7 +186,12 @@ func dataFor(
if file == "" {
return result, ErrNoDarwin64Build
}
sum, err := sha256sum.For("dist/" + file + "." + ctx.Config.Archive.Format)
sum, err := sha256sum.For(
filepath.Join(
ctx.Config.TargetFolder,
file+"."+ctx.Config.Archive.Format,
),
)
if err != nil {
return
}

View File

@ -5,6 +5,7 @@ import (
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
@ -62,7 +63,11 @@ func (Pipe) Run(ctx *context.Context) error {
func build(name, goos, goarch string, ctx *context.Context) error {
ldflags := ctx.Config.Build.Ldflags + " -X main.version=" + ctx.Version
output := "dist/" + name + "/" + ctx.Config.Build.Binary + extFor(goos)
output := filepath.Join(
ctx.Config.TargetFolder,
name,
ctx.Config.Build.Binary+extFor(goos),
)
log.Println("Building", output)
cmd := []string{"go", "build"}
if ctx.Config.Build.Flags != "" {

View File

@ -1,6 +1,9 @@
package build
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
@ -34,3 +37,43 @@ func TestBuild(t *testing.T) {
}
assert.NoError(build("build_test", runtime.GOOS, runtime.GOARCH, ctx))
}
func TestRunFullPipe(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
var binary = filepath.Join(folder, "testing")
var pre = filepath.Join(folder, "pre")
var post = filepath.Join(folder, "post")
var config = config.Project{
TargetFolder: folder,
Build: config.Build{
Binary: "testing",
Flags: "-v",
Ldflags: "-X main.test=testing",
Hooks: config.Hooks{
Pre: "touch " + pre,
Post: "touch " + post,
},
Goos: []string{
runtime.GOOS,
},
Goarch: []string{
runtime.GOARCH,
},
},
}
var ctx = &context.Context{
Config: config,
Archives: map[string]string{},
}
assert.NoError(Pipe{}.Run(ctx))
assert.True(exists(binary), binary)
assert.True(exists(pre), pre)
assert.True(exists(post), post)
}
func exists(file string) bool {
_, err := os.Stat(file)
return !os.IsNotExist(err)
}

View File

@ -82,6 +82,7 @@ func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.Brew.Install == "" {
ctx.Config.Brew.Install = "bin.install \"" + ctx.Config.Build.Binary + "\""
}
ctx.Config.TargetFolder = "dist"
return nil
}

View File

@ -54,7 +54,7 @@ func (Pipe) Run(ctx *context.Context) error {
}
func create(ctx *context.Context, format, archive, arch string) error {
var path = filepath.Join("dist", archive)
var path = filepath.Join(ctx.Config.TargetFolder, archive)
var file = path + ".deb"
var name = ctx.Config.Build.Binary
log.Println("Creating", file)

View File

@ -89,7 +89,7 @@ func description(diff string) string {
func upload(ctx *context.Context, client *github.Client, releaseID int, archive, format string) error {
archive = archive + "." + format
var path = filepath.Join("dist", archive)
var path = filepath.Join(ctx.Config.TargetFolder, archive)
// In case the file doesn't exist, we just ignore it.
// We do this because we can get invalid combinations of archive+format here,
// like darwinamd64 + deb or something like that.