2020-07-30 04:12:40 +02:00
|
|
|
//+build acceptance
|
|
|
|
|
2018-03-11 18:58:53 +01:00
|
|
|
package acceptance
|
|
|
|
|
2018-03-11 19:14:24 +01:00
|
|
|
import (
|
2018-06-04 14:08:27 +02:00
|
|
|
"fmt"
|
2019-10-09 21:10:05 +02:00
|
|
|
"io/ioutil"
|
2018-03-11 19:14:24 +01:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/goreleaser/nfpm"
|
|
|
|
// shut up
|
|
|
|
_ "github.com/goreleaser/nfpm/deb"
|
|
|
|
_ "github.com/goreleaser/nfpm/rpm"
|
|
|
|
)
|
|
|
|
|
2019-03-04 14:14:05 +01:00
|
|
|
// nolint: gochecknoglobals
|
2018-06-04 14:08:27 +02:00
|
|
|
var formats = []string{"deb", "rpm"}
|
|
|
|
|
|
|
|
func TestSimple(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
2019-03-04 14:14:05 +01:00
|
|
|
format := format
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
t.Parallel()
|
2018-07-09 04:20:39 +02:00
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("simple_%s", format),
|
|
|
|
Conf: "simple.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.dockerfile", format),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("i386-%s", format), func(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
t.Parallel()
|
2018-07-09 04:20:39 +02:00
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("simple_%s_386", format),
|
|
|
|
Conf: "simple.386.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.386.dockerfile", format),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("ppc64le-%s", format), func(t *testing.T) {
|
2019-03-20 01:54:42 +01:00
|
|
|
t.Skip("for some reason travis fails to run those")
|
2019-03-20 01:34:06 +01:00
|
|
|
t.Parallel()
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("simple_%s_ppc64le", format),
|
|
|
|
Conf: "simple.ppc64le.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.ppc64le.dockerfile", format),
|
|
|
|
})
|
|
|
|
})
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("arm64-%s", format), func(t *testing.T) {
|
2019-06-28 19:14:45 +02:00
|
|
|
t.Parallel()
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("simple_%s_arm64", format),
|
|
|
|
Conf: "simple.arm64.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.arm64.dockerfile", format),
|
|
|
|
})
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestComplex(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
2019-03-04 14:14:05 +01:00
|
|
|
format := format
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
t.Parallel()
|
2018-07-09 04:20:39 +02:00
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("complex_%s", format),
|
|
|
|
Conf: "complex.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.complex.dockerfile", format),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("i386-%s", format), func(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
t.Parallel()
|
2018-07-09 04:20:39 +02:00
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("complex_%s_386", format),
|
|
|
|
Conf: "complex.386.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.386.complex.dockerfile", format),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
2019-10-10 03:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvVarVersion(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
|
|
|
format := format
|
|
|
|
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
os.Setenv("SEMVER", "v1.0.0-0.1.b1+git.abcdefgh")
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("env-var-version_%s", format),
|
|
|
|
Conf: "env-var-version.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.env-var-version.dockerfile", format),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2018-06-04 14:08:27 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 21:10:05 +02:00
|
|
|
func TestComplexOverrides(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
for _, format := range formats {
|
2019-03-04 14:14:05 +01:00
|
|
|
format := format
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
t.Parallel()
|
2018-07-09 04:20:39 +02:00
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("overrides_%s", format),
|
|
|
|
Conf: "overrides.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.overrides.dockerfile", format),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 21:10:05 +02:00
|
|
|
func TestMin(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
for _, format := range formats {
|
2019-03-04 14:14:05 +01:00
|
|
|
format := format
|
2019-10-09 21:10:05 +02:00
|
|
|
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
|
2018-06-04 14:08:27 +02:00
|
|
|
t.Parallel()
|
2018-07-09 04:20:39 +02:00
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("min_%s", format),
|
|
|
|
Conf: "min.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.min.dockerfile", format),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 07:05:33 +02:00
|
|
|
func TestMeta(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
|
|
|
format := format
|
|
|
|
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("meta_%s", format),
|
|
|
|
Conf: "meta.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.meta.dockerfile", format),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 15:49:04 +02:00
|
|
|
func TestRPMCompression(t *testing.T) {
|
|
|
|
compressFormats := []string{"gzip", "xz", "lzma"}
|
|
|
|
for _, format := range compressFormats {
|
|
|
|
format := format
|
|
|
|
t.Run(format, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("%s_compression_rpm", format),
|
|
|
|
Conf: fmt.Sprintf("%s.compression.yaml", format),
|
|
|
|
Format: "rpm",
|
|
|
|
Dockerfile: fmt.Sprintf("%s.rpm.compression.dockerfile", format),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 17:12:38 +02:00
|
|
|
func TestRPMRelease(t *testing.T) {
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: "release_rpm",
|
|
|
|
Conf: "release.rpm.yaml",
|
|
|
|
Format: "rpm",
|
|
|
|
Dockerfile: "release.rpm.dockerfile",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-31 15:21:28 +02:00
|
|
|
func TestDebRules(t *testing.T) {
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: "rules.deb",
|
|
|
|
Conf: "rules.deb.yaml",
|
|
|
|
Format: "deb",
|
|
|
|
Dockerfile: "rules.deb.dockerfile",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-13 17:10:03 +02:00
|
|
|
func TestChangelog(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
|
|
|
format := format
|
|
|
|
t.Run(fmt.Sprintf("changelog-%s", format), func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: fmt.Sprintf("changelog_%s", format),
|
|
|
|
Conf: "withchangelog.yaml",
|
|
|
|
Format: format,
|
|
|
|
Dockerfile: fmt.Sprintf("%s.changelog.dockerfile", format),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 18:22:06 +02:00
|
|
|
func TestDebTriggers(t *testing.T) {
|
|
|
|
t.Run("triggers-deb", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
accept(t, acceptParms{
|
|
|
|
Name: "triggers-deb",
|
|
|
|
Conf: "triggers.yaml",
|
|
|
|
Format: "deb",
|
|
|
|
Dockerfile: "deb.triggers.dockerfile",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-09 04:20:39 +02:00
|
|
|
type acceptParms struct {
|
|
|
|
Name string
|
|
|
|
Conf string
|
|
|
|
Format string
|
|
|
|
Dockerfile string
|
|
|
|
}
|
|
|
|
|
|
|
|
func accept(t *testing.T, params acceptParms) {
|
|
|
|
var configFile = filepath.Join("./testdata", params.Conf)
|
2018-03-11 19:14:24 +01:00
|
|
|
tmp, err := filepath.Abs("./testdata/tmp")
|
|
|
|
require.NoError(t, err)
|
2018-07-09 04:20:39 +02:00
|
|
|
var packageName = params.Name + "." + params.Format
|
2018-03-11 19:24:44 +01:00
|
|
|
var target = filepath.Join(tmp, packageName)
|
2018-03-11 19:14:24 +01:00
|
|
|
|
|
|
|
require.NoError(t, os.MkdirAll(tmp, 0700))
|
|
|
|
|
2018-04-19 03:15:58 +02:00
|
|
|
config, err := nfpm.ParseFile(configFile)
|
2018-03-11 19:14:24 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-07-09 04:20:39 +02:00
|
|
|
info, err := config.Get(params.Format)
|
2018-03-11 19:14:24 +01:00
|
|
|
require.NoError(t, err)
|
2018-04-05 04:13:47 +02:00
|
|
|
require.NoError(t, nfpm.Validate(info))
|
|
|
|
|
2018-07-09 04:20:39 +02:00
|
|
|
pkg, err := nfpm.Get(params.Format)
|
2018-03-11 19:14:24 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
f, err := os.Create(target)
|
|
|
|
require.NoError(t, err)
|
2019-11-11 22:57:10 +01:00
|
|
|
info.Target = target
|
2018-03-11 19:14:24 +01:00
|
|
|
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
|
2018-09-12 18:17:59 +02:00
|
|
|
//nolint:gosec
|
2018-03-11 19:14:24 +01:00
|
|
|
cmd := exec.Command(
|
2018-05-17 02:00:11 +02:00
|
|
|
"docker", "build", "--rm", "--force-rm",
|
2018-07-09 04:20:39 +02:00
|
|
|
"-f", params.Dockerfile,
|
2018-05-17 01:36:03 +02:00
|
|
|
"--build-arg", "package="+filepath.Join("tmp", packageName),
|
|
|
|
".",
|
2018-03-11 19:14:24 +01:00
|
|
|
)
|
2018-05-17 01:36:03 +02:00
|
|
|
cmd.Dir = "./testdata"
|
2019-10-09 21:10:05 +02:00
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
|
|
require.NoError(t, err)
|
|
|
|
stderr, err := cmd.StderrPipe()
|
|
|
|
require.NoError(t, err)
|
2018-03-11 19:14:24 +01:00
|
|
|
t.Log("will exec:", cmd.Args)
|
2019-10-09 21:10:05 +02:00
|
|
|
err = cmd.Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var slurp []byte
|
|
|
|
slurp, err = ioutil.ReadAll(stderr)
|
|
|
|
if len(slurp) > 0 {
|
|
|
|
t.Log("stderr:", string(slurp))
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
slurp, err = ioutil.ReadAll(stdout)
|
|
|
|
if len(slurp) > 0 {
|
|
|
|
t.Log("stdout:", string(slurp))
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = cmd.Wait()
|
2018-03-11 19:14:24 +01:00
|
|
|
require.NoError(t, err)
|
2018-03-11 18:58:53 +01:00
|
|
|
}
|