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"
|
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"
|
|
|
|
)
|
|
|
|
|
2018-06-04 14:08:27 +02:00
|
|
|
var formats = []string{"deb", "rpm"}
|
|
|
|
|
|
|
|
func TestSimple(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
|
|
|
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),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
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),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestComplex(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
|
|
|
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),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
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),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestComplexOverridesDeb(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
|
|
|
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),
|
|
|
|
})
|
2018-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMinDeb(t *testing.T) {
|
|
|
|
for _, format := range formats {
|
|
|
|
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-06-04 14:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
|
2018-04-19 03:15:58 +02:00
|
|
|
bts, _ := exec.Command("pwd").CombinedOutput()
|
2018-03-11 19:14:24 +01:00
|
|
|
t.Log(string(bts))
|
|
|
|
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"
|
2018-03-11 19:14:24 +01:00
|
|
|
t.Log("will exec:", cmd.Args)
|
|
|
|
bts, err = cmd.CombinedOutput()
|
|
|
|
t.Log("output:", string(bts))
|
|
|
|
require.NoError(t, err)
|
2018-03-11 18:58:53 +01:00
|
|
|
}
|