1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/brew/brew_test.go

75 lines
2.3 KiB
Go
Raw Normal View History

2016-12-29 14:55:35 +02:00
package brew
import (
"testing"
2016-12-29 14:56:51 +02:00
2017-01-06 15:13:17 +02:00
"github.com/stretchr/testify/assert"
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{
BinaryName: "test",
Desc: "Some desc",
Homepage: "https://google.com",
Name: "Test",
Repo: "caarlos0/test",
Tag: "v0.1.3",
2017-01-30 02:01:26 +02:00
Version: "0.1.3",
2017-01-11 18:28:12 +02:00
File: "test_Darwin_x86_64",
2017-01-11 18:08:29 +02:00
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
2017-01-06 17:52:14 +02:00
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")
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
}