1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-22 04:08:49 +02:00

improved brew tests

This commit is contained in:
Carlos Alexandro Becker 2016-12-31 17:02:25 -02:00
parent ab473df425
commit bf6ff3dee7
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 43 additions and 33 deletions

View File

@ -26,9 +26,11 @@ const formulae = `class {{ .Name }} < Formula
bin.install "{{ .BinaryName }}"
end
{{ if .Caveats }}def caveats
{{ if .Caveats }}
def caveats
"{{ .Caveats }}"
end{{ end }}
end
{{ end }}
end
`

View File

@ -18,35 +18,43 @@ func TestSimpleName(t *testing.T) {
assert.Equal(t, formulaNameFor("binary"), "Binary")
}
var testFormulaeExpected = `class Test < Formula
desc "Some desc"
homepage "https://google.com"
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_#{%x(uname -s).gsub(/\n/, '')}_#{%x(uname -m).gsub(/\n/, '')}.tar.gz"
head "https://github.com/caarlos0/test.git"
version "v0.1.3"
def install
bin.install "test"
end
def caveats
"Here are some caveats"
end
end
`
func TestFormulae(t *testing.T) {
assert := assert.New(t)
out, err := doBuildFormulae(templateData{
BinaryName: "test",
Desc: "Some desc",
Homepage: "https://google.com",
Name: "Test",
Repo: "caarlos0/test",
Tag: "v0.1.3",
Caveats: "Here are some caveats",
})
assert.NoError(err)
assert.NoError(err)
assert.Equal(testFormulaeExpected, out.String())
var defaultTemplateData = templateData{
BinaryName: "test",
Desc: "Some desc",
Homepage: "https://google.com",
Name: "Test",
Repo: "caarlos0/test",
Tag: "v0.1.3",
}
func assertDefaultTemplateData(t *testing.T, formulae string) {
assert := assert.New(t)
assert.Contains(formulae, "class Test < Formula")
assert.Contains(formulae, "homepage \"https://google.com\"")
assert.Contains(formulae, "url \"https://github.com/caarlos0/test/releases/download/v0.1.3/test_#{%x(uname -s).gsub(/\\n/, '')}_#{%x(uname -m).gsub(/\\n/, '')}.tar.gz\"")
assert.Contains(formulae, "head \"https://github.com/caarlos0/test.git\"")
assert.Contains(formulae, "version \"v0.1.3\"")
assert.Contains(formulae, "bin.install \"test\"")
}
func TestFullFormulae(t *testing.T) {
assert := assert.New(t)
data := defaultTemplateData
data.Caveats = "Here are some caveats"
out, err := doBuildFormulae(data)
assert.NoError(err)
formulae := out.String()
assertDefaultTemplateData(t, formulae)
assert.Contains(formulae, "def caveats")
assert.Contains(formulae, "Here are some caveats")
}
func TestFormulaeNoCaveats(t *testing.T) {
assert := assert.New(t)
out, err := doBuildFormulae(defaultTemplateData)
assert.NoError(err)
formulae := out.String()
assertDefaultTemplateData(t, formulae)
assert.NotContains(formulae, "def caveats")
}