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-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
|
|
|
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",
|
2017-07-01 20:59:16 -03:00
|
|
|
File: "test_Darwin_x86_64.tar.gz",
|
2017-03-22 21:29:14 -03:00
|
|
|
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
|
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-07-16 15:06:32 -03:00
|
|
|
data.Dependencies = []string{"gtk+"}
|
|
|
|
data.Conflicts = []string{"svn"}
|
2017-03-09 14:24:49 -03:00
|
|
|
data.Plist = "it works"
|
|
|
|
data.Install = []string{"custom install script", "another install script"}
|
2017-07-16 15:06:32 -03:00
|
|
|
data.Tests = []string{`system "#{bin}/foo -version"`}
|
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()
|
2017-07-16 15:06:32 -03:00
|
|
|
|
|
|
|
f, err := os.Open("testdata/test.rb")
|
|
|
|
assert.NoError(err)
|
|
|
|
bts, err := ioutil.ReadAll(f)
|
|
|
|
assert.NoError(err)
|
|
|
|
|
|
|
|
assert.Equal(string(bts), formulae)
|
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
|
|
|
|
2017-07-16 16:01:20 -03:00
|
|
|
func TestSplit(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var parts = split("system \"true\"\nsystem \"#{bin}/foo -h\"")
|
|
|
|
assert.Equal([]string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts)
|
|
|
|
}
|
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)
|
|
|
|
var ctx = &context.Context{
|
2017-07-16 16:01:20 -03:00
|
|
|
Git: context.GitInfo{
|
|
|
|
CurrentTag: "v1.0.1",
|
|
|
|
},
|
|
|
|
Version: "1.0.1",
|
2017-03-26 15:30:21 -03:00
|
|
|
Config: config.Project{
|
2017-07-16 16:01:20 -03:00
|
|
|
Dist: folder,
|
|
|
|
ProjectName: "run-pipe",
|
2017-03-26 15:30:21 -03:00
|
|
|
Archive: config.Archive{
|
|
|
|
Format: "tar.gz",
|
|
|
|
},
|
|
|
|
Brew: config.Homebrew{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
2017-07-16 16:01:20 -03:00
|
|
|
Description: "A run pipe test formula",
|
|
|
|
Homepage: "https://github.com/goreleaser",
|
|
|
|
Caveats: "don't do this",
|
|
|
|
Test: "system \"true\"\nsystem \"#{bin}/foo -h\"",
|
|
|
|
Plist: `<xml>whatever</xml>`,
|
|
|
|
Dependencies: []string{"zsh"},
|
|
|
|
Conflicts: []string{"gtk+"},
|
|
|
|
Install: `bin.install "foo"`,
|
2017-03-26 15:30:21 -03:00
|
|
|
},
|
|
|
|
},
|
2017-04-18 13:10:13 -03:00
|
|
|
Publish: true,
|
2017-03-26 15:30:21 -03:00
|
|
|
}
|
2017-07-13 22:46:21 -03:00
|
|
|
var path = filepath.Join(folder, "bin.tar.gz")
|
|
|
|
ctx.AddBinary("darwinamd64", "bin", "bin", path)
|
2017-03-26 15:30:21 -03:00
|
|
|
client := &DummyClient{}
|
2017-07-06 20:13:02 -03:00
|
|
|
assert.Error(doRun(ctx, client))
|
|
|
|
assert.False(client.CreatedFile)
|
|
|
|
|
2017-07-13 22:46:21 -03:00
|
|
|
_, err = os.Create(path)
|
2017-07-06 20:13:02 -03:00
|
|
|
assert.NoError(err)
|
2017-03-26 15:30:21 -03:00
|
|
|
assert.NoError(doRun(ctx, client))
|
|
|
|
assert.True(client.CreatedFile)
|
2017-07-16 16:01:20 -03:00
|
|
|
|
|
|
|
f, err := os.Open("testdata/run_pipe.rb")
|
|
|
|
assert.NoError(err)
|
|
|
|
bts, err := ioutil.ReadAll(f)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(string(bts), client.Content)
|
2017-03-26 15:30:21 -03:00
|
|
|
}
|
|
|
|
|
2017-07-02 12:01:59 -03:00
|
|
|
func TestRunPipeFormatOverride(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
|
|
|
assert.NoError(err)
|
2017-07-13 22:46:21 -03:00
|
|
|
var path = filepath.Join(folder, "bin.zip")
|
|
|
|
_, err = os.Create(path)
|
2017-07-02 12:01:59 -03:00
|
|
|
assert.NoError(err)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
Archive: config.Archive{
|
|
|
|
Format: "tar.gz",
|
|
|
|
FormatOverrides: []config.FormatOverride{
|
|
|
|
{
|
|
|
|
Format: "zip",
|
|
|
|
Goos: "darwin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Brew: config.Homebrew{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Publish: true,
|
|
|
|
}
|
2017-07-13 22:46:21 -03:00
|
|
|
ctx.AddBinary("darwinamd64", "bin", "bin", path)
|
2017-07-02 12:01:59 -03:00
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(doRun(ctx, client))
|
|
|
|
assert.True(client.CreatedFile)
|
|
|
|
assert.Contains(client.Content, "bin.zip")
|
|
|
|
}
|
|
|
|
|
2017-04-21 12:02:48 -03:00
|
|
|
func TestRunPipeNoDarwin64Build(t *testing.T) {
|
2017-04-14 15:49:37 -03:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-18 13:10:13 -03:00
|
|
|
Publish: true,
|
2017-04-14 15:49:37 -03:00
|
|
|
}
|
|
|
|
client := &DummyClient{}
|
|
|
|
assert.Equal(ErrNoDarwin64Build, doRun(ctx, client))
|
|
|
|
assert.False(client.CreatedFile)
|
|
|
|
}
|
|
|
|
|
2017-04-21 12:02:48 -03:00
|
|
|
func TestRunPipeBrewNotSetup(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
Publish: true,
|
|
|
|
}
|
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(doRun(ctx, client))
|
|
|
|
assert.False(client.CreatedFile)
|
|
|
|
}
|
|
|
|
|
2017-07-03 01:24:26 -03:00
|
|
|
func TestRunPipeBinaryRelease(t *testing.T) {
|
2017-04-14 15:49:37 -03:00
|
|
|
assert := assert.New(t)
|
2017-07-03 01:24:26 -03:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Publish: true,
|
|
|
|
Config: config.Project{
|
|
|
|
Archive: config.Archive{
|
|
|
|
Format: "binary",
|
|
|
|
},
|
|
|
|
Brew: config.Homebrew{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-13 20:46:27 -03:00
|
|
|
ctx.AddBinary("darwinamd64", "foo", "bar", "baz")
|
2017-04-14 15:49:37 -03:00
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(doRun(ctx, client))
|
|
|
|
assert.False(client.CreatedFile)
|
|
|
|
}
|
|
|
|
|
2017-04-18 13:10:13 -03:00
|
|
|
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-04-21 19:50:09 -03:00
|
|
|
func TestRunPipeDraftRelease(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
2017-04-21 19:55:25 -03:00
|
|
|
Publish: true,
|
2017-04-21 19:50:09 -03:00
|
|
|
Config: config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Draft: true,
|
|
|
|
},
|
2017-04-21 19:55:25 -03:00
|
|
|
Brew: config.Homebrew{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
2017-04-21 19:50:09 -03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(doRun(ctx, client))
|
|
|
|
assert.False(client.CreatedFile)
|
|
|
|
}
|
|
|
|
|
2017-06-08 11:41:09 +02:00
|
|
|
func TestRunPipeFormatBinary(t *testing.T) {
|
2017-06-05 18:28:29 +02:00
|
|
|
assert := assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Archive: config.Archive{
|
2017-06-08 11:41:09 +02:00
|
|
|
Format: "binary",
|
2017-06-05 18:28:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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-07-02 12:01:59 -03:00
|
|
|
Content string
|
2017-03-26 15:30:21 -03:00
|
|
|
}
|
|
|
|
|
2017-04-19 17:09:58 -03:00
|
|
|
func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
|
2017-03-26 15:30:21 -03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *DummyClient) CreateFile(ctx *context.Context, content bytes.Buffer, path string) (err error) {
|
|
|
|
client.CreatedFile = true
|
2017-07-02 12:01:59 -03:00
|
|
|
bts, _ := ioutil.ReadAll(&content)
|
|
|
|
client.Content = string(bts)
|
2017-03-26 15:30:21 -03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *DummyClient) Upload(ctx *context.Context, releaseID int, name string, file *os.File) (err error) {
|
|
|
|
return
|
|
|
|
}
|