2018-03-11 18:58:53 +01:00
|
|
|
package acceptance
|
|
|
|
|
2018-03-11 19:14:24 +01:00
|
|
|
import (
|
|
|
|
"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-03-11 19:19:10 +01:00
|
|
|
func accept(t *testing.T, name, conf, format, dockerfile string) {
|
2018-04-19 03:15:58 +02:00
|
|
|
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))
|
|
|
|
|
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-04-19 03:15:58 +02:00
|
|
|
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))
|
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-05-17 01:36:03 +02:00
|
|
|
"-f", dockerfile,
|
|
|
|
"--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
|
|
|
}
|