mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-23 12:18:50 +02:00
brew tests
This commit is contained in:
parent
ee5bed9927
commit
4b66e8ea01
@ -88,6 +88,11 @@ func (Pipe) Description() string {
|
|||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(ctx *context.Context) error {
|
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
|
// TODO: remove this block in next release cycle
|
||||||
if ctx.Config.Brew.Repo != "" {
|
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.")
|
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 == "" {
|
if ctx.Config.Brew.GitHub.Name == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
client := clients.NewGitHubClient(ctx)
|
|
||||||
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb")
|
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb")
|
||||||
|
|
||||||
log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String())
|
log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String())
|
||||||
content, err := buildFormula(ctx, client)
|
content, err := buildFormula(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.CreateFile(ctx, content, path)
|
return client.CreateFile(ctx, content, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,10 +177,10 @@ func getInfo(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if info.Homepage != "" {
|
if info.Homepage == "" {
|
||||||
homepage = info.Homepage
|
|
||||||
} else {
|
|
||||||
homepage = info.URL
|
homepage = info.URL
|
||||||
|
} else {
|
||||||
|
homepage = info.Homepage
|
||||||
}
|
}
|
||||||
if info.Description == "" {
|
if info.Description == "" {
|
||||||
description = "TODO"
|
description = "TODO"
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package brew
|
package brew
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/clients"
|
||||||
"github.com/goreleaser/goreleaser/config"
|
"github.com/goreleaser/goreleaser/config"
|
||||||
|
"github.com/goreleaser/goreleaser/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,3 +86,52 @@ func TestFormulaeSimple(t *testing.T) {
|
|||||||
assert.NotContains(formulae, "depends_on")
|
assert.NotContains(formulae, "depends_on")
|
||||||
assert.NotContains(formulae, "def plist;")
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user