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

178 lines
4.6 KiB
Go
Raw Normal View History

2016-12-29 10:55:35 -02:00
package brew
import (
2017-03-26 15:30:21 -03:00
"bytes"
"io/ioutil"
"os"
"path/filepath"
2016-12-29 10:55:35 -02:00
"testing"
2016-12-29 10:56:51 -02:00
2017-04-14 16:07:27 -03:00
"github.com/goreleaser/goreleaser/client"
2017-03-22 21:01:29 -03:00
"github.com/goreleaser/goreleaser/config"
2017-03-26 15:30:21 -03:00
"github.com/goreleaser/goreleaser/context"
2017-01-06 11:13:17 -02:00
"github.com/stretchr/testify/assert"
2016-12-29 10:55:35 -02:00
)
2017-03-25 20:43:42 -03:00
func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.Description())
}
2016-12-29 10:55:35 -02:00
func TestNameWithDash(t *testing.T) {
assert.Equal(t, formulaNameFor("some-binary"), "SomeBinary")
}
func TestNameWithUnderline(t *testing.T) {
assert.Equal(t, formulaNameFor("some_binary"), "SomeBinary")
}
func TestSimpleName(t *testing.T) {
assert.Equal(t, formulaNameFor("binary"), "Binary")
}
2016-12-29 13:14:52 -02:00
2016-12-31 17:02:25 -02:00
var defaultTemplateData = templateData{
2017-03-22 21:06:37 -03:00
Binary: "test",
Desc: "Some desc",
Homepage: "https://google.com",
Name: "Test",
2017-03-22 21:29:14 -03:00
Repo: config.Repo{
Owner: "caarlos0",
Name: "test",
},
Tag: "v0.1.3",
Version: "0.1.3",
File: "test_Darwin_x86_64",
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
Format: "tar.gz",
2016-12-31 17:02:25 -02:00
}
func assertDefaultTemplateData(t *testing.T, formulae string) {
assert := assert.New(t)
assert.Contains(formulae, "class Test < Formula")
assert.Contains(formulae, "homepage \"https://google.com\"")
2017-01-06 13:54:14 -02:00
assert.Contains(formulae, "url \"https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz\"")
2017-01-11 14:08:29 -02:00
assert.Contains(formulae, "sha256 \"1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68\"")
2017-01-29 22:01:26 -02:00
assert.Contains(formulae, "version \"0.1.3\"")
2016-12-31 17:02:25 -02:00
}
func TestFullFormulae(t *testing.T) {
2016-12-29 13:14:52 -02:00
assert := assert.New(t)
2016-12-31 17:02:25 -02:00
data := defaultTemplateData
data.Caveats = "Here are some caveats"
2017-01-17 08:33:43 -02:00
data.Dependencies = []string{"gtk", "git"}
2017-02-01 15:40:27 -02:00
data.Conflicts = []string{"conflicting_dep"}
2017-03-09 14:24:49 -03:00
data.Plist = "it works"
data.Install = []string{"custom install script", "another install script"}
2017-01-19 10:04:41 +01:00
out, err := doBuildFormula(data)
2016-12-29 13:14:52 -02:00
assert.NoError(err)
2016-12-31 17:02:25 -02:00
formulae := out.String()
assertDefaultTemplateData(t, formulae)
assert.Contains(formulae, "def caveats")
assert.Contains(formulae, "Here are some caveats")
assert.Contains(formulae, "depends_on \"gtk\"")
assert.Contains(formulae, "depends_on \"git\"")
2017-02-01 15:40:27 -02:00
assert.Contains(formulae, "conflicts_with \"conflicting_dep\"")
2017-03-09 14:24:49 -03:00
assert.Contains(formulae, "custom install script")
assert.Contains(formulae, "another install script")
2017-02-21 16:04:57 +01:00
assert.Contains(formulae, "def plist;")
2016-12-31 17:02:25 -02:00
}
2017-02-01 15:40:27 -02:00
func TestFormulaeSimple(t *testing.T) {
2016-12-31 17:02:25 -02:00
assert := assert.New(t)
2017-01-19 10:04:41 +01:00
out, err := doBuildFormula(defaultTemplateData)
2016-12-29 13:14:52 -02:00
assert.NoError(err)
2016-12-31 17:02:25 -02:00
formulae := out.String()
assertDefaultTemplateData(t, formulae)
assert.NotContains(formulae, "def caveats")
2017-01-17 08:33:43 -02:00
assert.NotContains(formulae, "depends_on")
2017-03-09 14:24:49 -03:00
assert.NotContains(formulae, "def plist;")
2016-12-29 13:14:52 -02:00
}
2017-03-26 15:30:21 -03:00
func TestRunPipe(t *testing.T) {
assert := assert.New(t)
2017-04-15 14:18:17 -03:00
folder, err := ioutil.TempDir("", "goreleasertest")
2017-03-26 15:30:21 -03:00
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",
},
Publish: true,
2017-03-26 15:30:21 -03:00
}
client := &DummyClient{}
assert.NoError(doRun(ctx, client))
assert.True(client.CreatedFile)
}
2017-04-14 15:49:37 -03:00
func TestRunPipeBrewNotSetup(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Archive: config.Archive{
Format: "tar.gz",
},
Brew: config.Homebrew{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
},
Publish: true,
2017-04-14 15:49:37 -03:00
}
client := &DummyClient{}
assert.Equal(ErrNoDarwin64Build, doRun(ctx, client))
assert.False(client.CreatedFile)
}
func TestRunPipeNoDarwinBuild(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{}
client := &DummyClient{}
assert.NoError(doRun(ctx, client))
assert.False(client.CreatedFile)
}
func TestRunPipeNoPublish(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{
Publish: false,
}
client := &DummyClient{}
assert.NoError(doRun(ctx, client))
assert.False(client.CreatedFile)
}
2017-03-26 15:30:21 -03:00
type DummyClient struct {
CreatedFile bool
}
2017-04-14 16:07:27 -03:00
func (client *DummyClient) GetInfo(ctx *context.Context) (info client.Info, err error) {
2017-03-26 15:30:21 -03:00
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
}