1
1
mirror of https://github.com/goreleaser/nfpm synced 2024-11-18 19:04:07 +01:00
nfpm/acceptance/acceptance_test.go

160 lines
3.9 KiB
Go
Raw Normal View History

2018-03-11 18:58:53 +01:00
package acceptance
2018-03-11 19:14:24 +01:00
import (
"fmt"
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
var formats = []string{"deb", "rpm"}
func TestSimple(t *testing.T) {
for _, format := range formats {
2019-03-04 14:14:05 +01:00
format := format
t.Run("amd64", func(t *testing.T) {
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),
})
})
t.Run("i386", func(t *testing.T) {
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),
})
})
2019-03-20 01:34:06 +01:00
t.Run("ppc64le", 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),
})
})
t.Run("arm64", func(t *testing.T) {
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),
})
})
}
}
func TestComplex(t *testing.T) {
for _, format := range formats {
2019-03-04 14:14:05 +01:00
format := format
t.Run("amd64", func(t *testing.T) {
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),
})
})
t.Run("i386", func(t *testing.T) {
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),
})
})
}
}
func TestComplexOverridesDeb(t *testing.T) {
for _, format := range formats {
2019-03-04 14:14:05 +01:00
format := format
t.Run("amd64", func(t *testing.T) {
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),
})
})
}
}
func TestMinDeb(t *testing.T) {
for _, format := range formats {
2019-03-04 14:14:05 +01:00
format := format
t.Run("amd64", func(t *testing.T) {
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-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))
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)
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(
"docker", "build", "--rm", "--force-rm",
2018-07-09 04:20:39 +02:00
"-f", params.Dockerfile,
"--build-arg", "package="+filepath.Join("tmp", packageName),
".",
2018-03-11 19:14:24 +01:00
)
cmd.Dir = "./testdata"
2018-03-11 19:14:24 +01:00
t.Log("will exec:", cmd.Args)
2018-09-12 18:17:59 +02:00
bts, err := cmd.CombinedOutput()
2018-03-11 19:14:24 +01:00
t.Log("output:", string(bts))
require.NoError(t, err)
2018-03-11 18:58:53 +01:00
}