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

322 lines
8.0 KiB
Go
Raw Normal View History

//+build acceptance
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
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
_ "github.com/goreleaser/nfpm/apk"
2018-03-11 19:14:24 +01:00
_ "github.com/goreleaser/nfpm/deb"
_ "github.com/goreleaser/nfpm/rpm"
)
2019-03-04 14:14:05 +01:00
// nolint: gochecknoglobals
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
var formats = []string{"deb", "rpm", "apk"}
func TestSimple(t *testing.T) {
for _, format := range formats {
2019-03-04 14:14:05 +01:00
format := format
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
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(fmt.Sprintf("i386-%s", format), func(t *testing.T) {
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),
})
})
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
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(fmt.Sprintf("arm64-%s", format), func(t *testing.T) {
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(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
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(fmt.Sprintf("i386-%s", format), func(t *testing.T) {
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 TestConfigNoReplace(t *testing.T) {
var target = "./testdata/tmp/noreplace_old_rpm.rpm"
require.NoError(t, os.MkdirAll("./testdata/tmp", 0700))
config, err := nfpm.ParseFile("./testdata/config-noreplace-old.yaml")
require.NoError(t, err)
info, err := config.Get("rpm")
require.NoError(t, err)
require.NoError(t, nfpm.Validate(info))
pkg, err := nfpm.Get("rpm")
require.NoError(t, err)
f, err := os.Create(target)
require.NoError(t, err)
info.Target = target
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
t.Run("noreplace-rpm", func(t *testing.T) {
accept(t, acceptParms{
Name: "noreplace_rpm",
Conf: "config-noreplace.yaml",
Format: "rpm",
Dockerfile: "rpm.config-noreplace.dockerfile",
})
})
}
func TestEnvVarVersion(t *testing.T) {
for _, format := range formats {
format := format
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
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),
})
})
}
}
func TestComplexOverrides(t *testing.T) {
for _, format := range formats {
2019-03-04 14:14:05 +01:00
format := format
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
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 TestMin(t *testing.T) {
for _, format := range formats {
2019-03-04 14:14:05 +01:00
format := format
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
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),
})
})
}
}
func TestMeta(t *testing.T) {
for _, format := range formats {
format := format
t.Run(fmt.Sprintf("amd64-%s", format), func(t *testing.T) {
accept(t, acceptParms{
Name: fmt.Sprintf("meta_%s", format),
Conf: "meta.yaml",
Format: format,
Dockerfile: fmt.Sprintf("%s.meta.dockerfile", format),
})
})
}
}
func TestRPMCompression(t *testing.T) {
compressFormats := []string{"gzip", "xz", "lzma"}
for _, format := range compressFormats {
format := format
t.Run(format, func(t *testing.T) {
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),
})
})
}
}
func TestRPMRelease(t *testing.T) {
accept(t, acceptParms{
Name: "release_rpm",
Conf: "release.rpm.yaml",
Format: "rpm",
Dockerfile: "release.rpm.dockerfile",
})
}
func TestDebRules(t *testing.T) {
accept(t, acceptParms{
Name: "rules.deb",
Conf: "rules.deb.yaml",
Format: "deb",
Dockerfile: "rules.deb.dockerfile",
})
}
func TestChangelog(t *testing.T) {
for _, format := range formats {
format := format
t.Run(fmt.Sprintf("changelog-%s", format), func(t *testing.T) {
accept(t, acceptParms{
Name: fmt.Sprintf("changelog_%s", format),
Conf: "withchangelog.yaml",
Format: format,
Dockerfile: fmt.Sprintf("%s.changelog.dockerfile", format),
})
})
}
}
func TestDebTriggers(t *testing.T) {
t.Run("triggers-deb", func(t *testing.T) {
accept(t, acceptParms{
Name: "triggers-deb",
Conf: "triggers.yaml",
Format: "deb",
Dockerfile: "deb.triggers.dockerfile",
})
})
}
func TestSymlink(t *testing.T) {
for _, format := range formats {
format := format
t.Run(fmt.Sprintf("symlink-%s", format), func(t *testing.T) {
accept(t, acceptParms{
Name: fmt.Sprintf("symlink_%s", format),
Conf: "symlink.yaml",
Format: format,
Dockerfile: fmt.Sprintf("%s.symlink.dockerfile", format),
})
})
}
}
func TestDebBreaks(t *testing.T) {
t.Run("breaks-deb", func(t *testing.T) {
accept(t, acceptParms{
Name: "breaks-deb",
Conf: "breaks.yaml",
Format: "deb",
Dockerfile: "deb.breaks.dockerfile",
})
})
}
func TestSignatures(t *testing.T) {
for _, format := range formats {
format := format
t.Run("signed", func(t *testing.T) {
accept(t, acceptParms{
Name: fmt.Sprintf("signed_%s", format),
Conf: "signed.yaml",
Format: format,
Dockerfile: fmt.Sprintf("%s.signed.dockerfile", format),
})
})
}
}
2018-07-09 04:20:39 +02:00
type acceptParms struct {
Name string
Conf string
Format string
Dockerfile string
}
type testWriter struct {
t *testing.T
}
func (t testWriter) Write(p []byte) (n int, err error) {
t.t.Logf(string(p))
return len(p), nil
}
2018-07-09 04:20:39 +02:00
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)
feat: apk support (#207) * first attempt at apk, built from Issue #39 * inspector cleanups * read the contrib note, ran linter, fixes made. Noice! * linter went wonky * linter went wonky * fix some lint issues * fix some lint issues * lightweight file validation, while I try to refactor method into smaller chunks * refactorings to get `make ci` to pass. ain't pretty, but hopefully doesn't make things worse. * add ignore file to get workdir created in CI * try to get a successful test run on CI (file sizes differ on CI). * must remember to run liner (make ci) before pushing * Doh! Detect CI via correct env var name * tweak CI expected file sizes * blech. try to get a range of values for CI * better message if value fails conditions * better message if value fails conditions * initial impl of Package interface - just hoping I don't already have the arch mapping backwards. * missed non-altered arch case * ci failures * refactor io.File to Writer * add note about command to test apk install in docker * remove absolute paths from test (prep for replacement with info.Files). * rename test files folder * get ci file size ranges happy after path changes * get ci file size ranges happy after path changes * move COPY towards end, allowing more caching of layers - feedback from @tcurdt * remove Gz from function name * rename combine function * add skipVerify flag to preserve generated .apk file for use in dockerfile manual test. Thanks @tcurdt * make ci is my friend * remove useless comment * start conversion to nfpm.Info * use base64 encoded string for private signing key * remove old runit() method, as we can now test using Default.Package. add some tests lifted from deb_test.go. * duck and cover: register the apk packager * use the metadata from nfpm (does not handle scripts/pre/post, etc) * getting closer to removing size assertions, but not just yet * getting closer to removing size assertions, but not just yet * add niffty import for init - Blank identifier comes to the rescue. Thanks @tcurdt. add apk to overrides parse test. * I will very much enjoy deleting this assertion...soon, soon. * add PrivateKeyFile option, which is subordinate to PrivateKey * move PrivateKey configs to root config struct. expand PrivateKey configs from env vars if set. * provide the user a hint if privatekey config is missing for .apk packager * lovin' the linter now. learning language from linter loudness. didn't know switch could work like that. * add support for 'scripts' in control file * fix control metadata * make signing keyname configurable * goofy size fix * remove temporary test and related files * fix template copy/pasta error * remove old print statements * first take at integration tests. should remove need for --allow-untrusted in `apk add` command. * fix: merge issues, remove signature support Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: meta Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: datahash seems unused Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: improve test code Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: unused params Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: tests Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: changelog test Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: fix Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: img Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * test: symlink Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: uneeded deletes Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: symlinks Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Dan Rollo <danrollo@gmail.com>
2020-08-17 22:28:38 +02:00
t.Log("package: " + target)
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)
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(
"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"
cmd.Stderr = testWriter{t}
cmd.Stdout = cmd.Stderr
t.Log("will exec:", cmd.Args)
require.NoError(t, cmd.Run())
2018-03-11 18:58:53 +01:00
}