2016-12-29 14:55:35 +02:00
|
|
|
package brew
|
|
|
|
|
|
|
|
import (
|
2017-03-26 20:30:21 +02:00
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-12-29 14:55:35 +02:00
|
|
|
"testing"
|
2016-12-29 14:56:51 +02:00
|
|
|
|
2017-03-26 20:30:21 +02:00
|
|
|
"github.com/goreleaser/goreleaser/clients"
|
2017-03-23 02:01:29 +02:00
|
|
|
"github.com/goreleaser/goreleaser/config"
|
2017-03-26 20:30:21 +02:00
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-01-06 15:13:17 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-12-29 14:55:35 +02:00
|
|
|
)
|
|
|
|
|
2017-03-26 01:43:42 +02:00
|
|
|
func TestDescription(t *testing.T) {
|
|
|
|
assert.NotEmpty(t, Pipe{}.Description())
|
|
|
|
}
|
|
|
|
|
2016-12-29 14: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 17:14:52 +02:00
|
|
|
|
2016-12-31 21:02:25 +02:00
|
|
|
var defaultTemplateData = templateData{
|
2017-03-23 02:06:37 +02:00
|
|
|
Binary: "test",
|
|
|
|
Desc: "Some desc",
|
|
|
|
Homepage: "https://google.com",
|
|
|
|
Name: "Test",
|
2017-03-23 02:29:14 +02: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 21: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 17: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 18:08:29 +02:00
|
|
|
assert.Contains(formulae, "sha256 \"1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68\"")
|
2017-01-30 02:01:26 +02:00
|
|
|
assert.Contains(formulae, "version \"0.1.3\"")
|
2016-12-31 21:02:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFullFormulae(t *testing.T) {
|
2016-12-29 17:14:52 +02:00
|
|
|
assert := assert.New(t)
|
2016-12-31 21:02:25 +02:00
|
|
|
data := defaultTemplateData
|
|
|
|
data.Caveats = "Here are some caveats"
|
2017-01-17 12:33:43 +02:00
|
|
|
data.Dependencies = []string{"gtk", "git"}
|
2017-02-01 19:40:27 +02:00
|
|
|
data.Conflicts = []string{"conflicting_dep"}
|
2017-03-09 19:24:49 +02:00
|
|
|
data.Plist = "it works"
|
|
|
|
data.Install = []string{"custom install script", "another install script"}
|
2017-01-19 11:04:41 +02:00
|
|
|
out, err := doBuildFormula(data)
|
2016-12-29 17:14:52 +02:00
|
|
|
assert.NoError(err)
|
2016-12-31 21:02:25 +02:00
|
|
|
formulae := out.String()
|
|
|
|
assertDefaultTemplateData(t, formulae)
|
|
|
|
assert.Contains(formulae, "def caveats")
|
|
|
|
assert.Contains(formulae, "Here are some caveats")
|
2017-01-17 19:44:32 +02:00
|
|
|
assert.Contains(formulae, "depends_on \"gtk\"")
|
|
|
|
assert.Contains(formulae, "depends_on \"git\"")
|
2017-02-01 19:40:27 +02:00
|
|
|
assert.Contains(formulae, "conflicts_with \"conflicting_dep\"")
|
2017-03-09 19:24:49 +02:00
|
|
|
assert.Contains(formulae, "custom install script")
|
|
|
|
assert.Contains(formulae, "another install script")
|
2017-02-21 17:04:57 +02:00
|
|
|
assert.Contains(formulae, "def plist;")
|
2016-12-31 21:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-02-01 19:40:27 +02:00
|
|
|
func TestFormulaeSimple(t *testing.T) {
|
2016-12-31 21:02:25 +02:00
|
|
|
assert := assert.New(t)
|
2017-01-19 11:04:41 +02:00
|
|
|
out, err := doBuildFormula(defaultTemplateData)
|
2016-12-29 17:14:52 +02:00
|
|
|
assert.NoError(err)
|
2016-12-31 21:02:25 +02:00
|
|
|
formulae := out.String()
|
|
|
|
assertDefaultTemplateData(t, formulae)
|
|
|
|
assert.NotContains(formulae, "def caveats")
|
2017-01-17 12:33:43 +02:00
|
|
|
assert.NotContains(formulae, "depends_on")
|
2017-03-09 19:24:49 +02:00
|
|
|
assert.NotContains(formulae, "def plist;")
|
2016-12-29 17:14:52 +02:00
|
|
|
}
|
2017-03-26 20:30:21 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-04-14 20:49:37 +02: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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-03-26 20:30:21 +02:00
|
|
|
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
|
|
|
|
}
|