1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-06-13 05:06:13 +02:00
nfpm/acceptance/acceptance_test.go

100 lines
2.6 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"
)
var formats = []string{"deb", "rpm"}
func TestSimple(t *testing.T) {
for _, format := range formats {
t.Run("amd64", func(t *testing.T) {
t.Parallel()
accept(t, fmt.Sprintf("simple_%s", format), "simple.yaml", format, fmt.Sprintf("%s.dockerfile", format))
})
t.Run("i386", func(t *testing.T) {
t.Parallel()
accept(t, fmt.Sprintf("simple_%s_386", format), "simple.386.yaml", format, fmt.Sprintf("%s.386.dockerfile", format))
})
}
}
func TestComplex(t *testing.T) {
for _, format := range formats {
t.Run("amd64", func(t *testing.T) {
t.Parallel()
accept(t, fmt.Sprintf("complex_%s", format), "complex.yaml", format, fmt.Sprintf("%s.complex.dockerfile", format))
})
t.Run("i386", func(t *testing.T) {
t.Parallel()
accept(t, fmt.Sprintf("complex_%s_386", format), "complex.386.yaml", format, fmt.Sprintf("%s.386.complex.dockerfile", format))
})
}
}
func TestComplexOverridesDeb(t *testing.T) {
for _, format := range formats {
t.Run("amd64", func(t *testing.T) {
t.Parallel()
accept(t, fmt.Sprintf("overrides_%s", format), "overrides.yaml", format, fmt.Sprintf("%s.overrides.dockerfile", format))
})
}
}
func TestMinDeb(t *testing.T) {
for _, format := range formats {
t.Run("amd64", func(t *testing.T) {
t.Parallel()
accept(t, fmt.Sprintf("min_%s", format), "min.yaml", format, fmt.Sprintf("%s.min.dockerfile", format))
})
}
}
2018-03-11 19:19:10 +01:00
func accept(t *testing.T, name, conf, format, dockerfile string) {
var configFile = filepath.Join("./testdata", conf)
2018-03-11 19:14:24 +01:00
tmp, err := filepath.Abs("./testdata/tmp")
require.NoError(t, err)
2018-03-11 19:24:44 +01:00
var packageName = name + "." + format
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)
info, err := config.Get(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-03-11 19:14:24 +01:00
pkg, err := nfpm.Get(format)
require.NoError(t, err)
f, err := os.Create(target)
require.NoError(t, err)
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
bts, _ := exec.Command("pwd").CombinedOutput()
2018-03-11 19:14:24 +01:00
t.Log(string(bts))
cmd := exec.Command(
"docker", "build", "--rm", "--force-rm",
"-f", 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)
bts, err = cmd.CombinedOutput()
t.Log("output:", string(bts))
require.NoError(t, err)
2018-03-11 18:58:53 +01:00
}