1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

brew tests

This commit is contained in:
Carlos Alexandro Becker 2017-03-26 15:30:21 -03:00
parent ee5bed9927
commit 4b66e8ea01
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 63 additions and 6 deletions

View File

@ -88,6 +88,11 @@ func (Pipe) Description() string {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
client := clients.NewGitHubClient(ctx)
return doRun(ctx, client)
}
func doRun(ctx *context.Context, client clients.Client) error {
// TODO: remove this block in next release cycle
if ctx.Config.Brew.Repo != "" {
log.Println("The `brew.repo` syntax is deprecated and will soon be removed. Please check the README for more info.")
@ -100,15 +105,12 @@ func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.Brew.GitHub.Name == "" {
return nil
}
client := clients.NewGitHubClient(ctx)
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb")
log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String())
content, err := buildFormula(ctx, client)
if err != nil {
return err
}
return client.CreateFile(ctx, content, path)
}
@ -175,10 +177,10 @@ func getInfo(
if err != nil {
return
}
if info.Homepage != "" {
homepage = info.Homepage
} else {
if info.Homepage == "" {
homepage = info.URL
} else {
homepage = info.Homepage
}
if info.Description == "" {
description = "TODO"

View File

@ -1,9 +1,15 @@
package brew
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/clients"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert"
)
@ -80,3 +86,52 @@ func TestFormulaeSimple(t *testing.T) {
assert.NotContains(formulae, "depends_on")
assert.NotContains(formulae, "def plist;")
}
func TestRunPipe(t *testing.T) {
assert := assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
_, err = os.Create(filepath.Join(folder, "bin.tar.gz"))
assert.NoError(err)
var ctx = &context.Context{
Config: config.Project{
Dist: folder,
Archive: config.Archive{
Format: "tar.gz",
},
Brew: config.Homebrew{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
},
Archives: map[string]string{
"darwinamd64": "bin",
},
}
client := &DummyClient{}
assert.NoError(doRun(ctx, client))
assert.True(client.CreatedFile)
}
type DummyClient struct {
CreatedFile bool
}
func (client *DummyClient) GetInfo(ctx *context.Context) (info clients.Info, err error) {
return
}
func (client *DummyClient) CreateRelease(ctx *context.Context) (releaseID int, err error) {
return
}
func (client *DummyClient) CreateFile(ctx *context.Context, content bytes.Buffer, path string) (err error) {
client.CreatedFile = true
return
}
func (client *DummyClient) Upload(ctx *context.Context, releaseID int, name string, file *os.File) (err error) {
return
}