mirror of
https://github.com/goreleaser/nfpm
synced 2026-11-29 04:44:55 +01:00
macos-linux-build cross-compiles the test app and packages it as an installer package, an application bundle and a disk image, unsigned and signed with a throwaway certificate. Where the repository's Apple Developer ID identities are available it also signs with those. macos-verify takes those exact bytes to a macOS runner. The installer installs, upgrades, downgrades and refuses the packages, including ones with non-ASCII names and failing scripts; the bundles are unpacked and launched, the images mounted; pkgutil, codesign and the system trust stack check the signatures, and the signing certificate is compared by fingerprint. Both jobs run on pull requests as well as in the merge queue. macos-acceptance-tests reads all three formats back on Linux for both architectures, in the merge queue like the other structure tests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
681 lines
20 KiB
Go
681 lines
20 KiB
Go
//go:build acceptance
|
|
|
|
package nfpm_test
|
|
|
|
import (
|
|
"archive/zip"
|
|
"bytes"
|
|
"fmt"
|
|
"io/fs"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/goreleaser/nfpm/v2"
|
|
_ "github.com/goreleaser/nfpm/v2/apk"
|
|
_ "github.com/goreleaser/nfpm/v2/app"
|
|
_ "github.com/goreleaser/nfpm/v2/arch"
|
|
_ "github.com/goreleaser/nfpm/v2/deb"
|
|
_ "github.com/goreleaser/nfpm/v2/dmg"
|
|
_ "github.com/goreleaser/nfpm/v2/ipk"
|
|
_ "github.com/goreleaser/nfpm/v2/msi"
|
|
_ "github.com/goreleaser/nfpm/v2/msix"
|
|
_ "github.com/goreleaser/nfpm/v2/pkg"
|
|
_ "github.com/goreleaser/nfpm/v2/rpm"
|
|
"github.com/stretchr/testify/require"
|
|
gomsi "go.digitalxero.dev/go-msi"
|
|
osxdmg "go.digitalxero.dev/osx/dmg"
|
|
osxpkg "go.digitalxero.dev/osx/pkg"
|
|
)
|
|
|
|
// nolint: gochecknoglobals
|
|
var formatArchs = map[string][]string{
|
|
"apk": {"amd64", "arm64", "386", "ppc64le", "armv6", "armv7", "s390x"},
|
|
"deb": {"amd64", "arm64", "ppc64le", "armv7", "s390x"},
|
|
"ipk": {"x86_64", "aarch64_generic"},
|
|
"rpm": {"amd64", "arm64", "ppc64le"},
|
|
"archlinux": {"amd64"},
|
|
}
|
|
|
|
func TestCore(t *testing.T) {
|
|
t.Parallel()
|
|
testNames := []string{
|
|
"min",
|
|
"simple",
|
|
"no-glob",
|
|
"complex",
|
|
"env-var-version",
|
|
"overrides",
|
|
"meta",
|
|
"withchangelog",
|
|
"symlink",
|
|
"signed",
|
|
}
|
|
for _, name := range testNames {
|
|
for format, architecture := range formatArchs {
|
|
for _, arch := range architecture {
|
|
func(t *testing.T, testName, testFormat, testArch string) {
|
|
t.Run(fmt.Sprintf("%s/%s/%s", testFormat, testArch, testName), func(t *testing.T) {
|
|
t.Parallel()
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_%s", testName, testArch),
|
|
Conf: fmt.Sprintf("core.%s.yaml", testName),
|
|
Format: testFormat,
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("%s.dockerfile", testFormat),
|
|
Target: testName,
|
|
Arch: testArch,
|
|
},
|
|
})
|
|
})
|
|
}(t, name, format, arch)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUpgrade(t *testing.T) {
|
|
t.Parallel()
|
|
testNames := []string{
|
|
"upgrade",
|
|
}
|
|
for _, name := range testNames {
|
|
for format, architecture := range formatArchs {
|
|
for _, arch := range architecture {
|
|
func(t *testing.T, testName, testFormat, testArch string) {
|
|
t.Run(fmt.Sprintf("%s/%s/%s", testFormat, testArch, testName), func(t *testing.T) {
|
|
t.Parallel()
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
|
|
arch := strings.ReplaceAll(testArch, "armv", "arm/")
|
|
oldpkg := fmt.Sprintf("tmp/%s_%s.v1.%s", testName, testArch, testFormat)
|
|
target := fmt.Sprintf("./testdata/acceptance/%s", oldpkg)
|
|
require.NoError(t, os.MkdirAll("./testdata/acceptance/tmp", 0o700))
|
|
|
|
config, err := nfpm.ParseFileWithEnvMapping(
|
|
fmt.Sprintf("./testdata/acceptance/%s.v1.yaml", testName),
|
|
func(s string) string {
|
|
switch s {
|
|
case "BUILD_ARCH":
|
|
return strings.ReplaceAll(arch, "/", "")
|
|
case "SEMVER":
|
|
return "v1.0.0-0.1.b1+git.abcdefgh"
|
|
default:
|
|
return os.Getenv(s)
|
|
}
|
|
},
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
info, err := config.Get(testFormat)
|
|
require.NoError(t, err)
|
|
require.NoError(t, nfpm.Validate(info))
|
|
|
|
pkg, err := nfpm.Get(testFormat)
|
|
require.NoError(t, err)
|
|
|
|
f, err := os.Create(target)
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() { require.NoError(t, f.Close()) })
|
|
info.Target = target
|
|
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
|
|
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_%s.v2", testName, testArch),
|
|
Conf: fmt.Sprintf("%s.v2.yaml", testName),
|
|
Format: testFormat,
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("%s.dockerfile", testFormat),
|
|
Target: testName,
|
|
Arch: testArch,
|
|
BuildArgs: []string{fmt.Sprintf("oldpackage=%s", oldpkg)},
|
|
},
|
|
})
|
|
})
|
|
}(t, name, format, arch)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRPMCompression(t *testing.T) {
|
|
t.Parallel()
|
|
format := "rpm"
|
|
compressFormats := []string{"gzip", "xz", "lzma", "zstd"}
|
|
for _, arch := range formatArchs[format] {
|
|
for _, compFormat := range compressFormats {
|
|
func(t *testing.T, testCompFormat, testArch string) {
|
|
t.Run(fmt.Sprintf("%s/%s/%s", format, testArch, testCompFormat), func(t *testing.T) {
|
|
t.Parallel()
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_compression_%s", testCompFormat, testArch),
|
|
Conf: fmt.Sprintf("rpm.%s.compression.yaml", testCompFormat),
|
|
Format: format,
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("%s.dockerfile", format),
|
|
Target: "compression",
|
|
Arch: testArch,
|
|
BuildArgs: []string{fmt.Sprintf("compression=%s", testCompFormat)},
|
|
},
|
|
})
|
|
})
|
|
}(t, compFormat, arch)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDebCompression(t *testing.T) {
|
|
t.Parallel()
|
|
format := "deb"
|
|
compressFormats := []string{"gzip", "xz", "zstd", "none"}
|
|
for _, arch := range formatArchs[format] {
|
|
for _, compFormat := range compressFormats {
|
|
func(t *testing.T, testCompFormat, testArch string) {
|
|
t.Run(fmt.Sprintf("%s/%s/%s", format, testArch, testCompFormat), func(t *testing.T) {
|
|
t.Parallel()
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_compression_%s", testCompFormat, testArch),
|
|
Conf: fmt.Sprintf("deb.%s.compression.yaml", testCompFormat),
|
|
Format: format,
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("%s.dockerfile", format),
|
|
Target: "compression",
|
|
Arch: testArch,
|
|
},
|
|
})
|
|
})
|
|
}(t, compFormat, arch)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRPMSpecific(t *testing.T) {
|
|
t.Parallel()
|
|
format := "rpm"
|
|
testNames := []string{
|
|
"release",
|
|
"directories",
|
|
"verify",
|
|
"postrequires",
|
|
"elfcolors",
|
|
"isaprovide",
|
|
"scriptrequires",
|
|
}
|
|
for _, name := range testNames {
|
|
for _, arch := range formatArchs[format] {
|
|
func(t *testing.T, testName, testArch string) {
|
|
t.Run(fmt.Sprintf("%s/%s/%s", format, testArch, testName), func(t *testing.T) {
|
|
t.Parallel()
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_%s", testName, testArch),
|
|
Conf: fmt.Sprintf("%s.%s.yaml", format, testName),
|
|
Format: format,
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("%s.dockerfile", format),
|
|
Target: testName,
|
|
Arch: testArch,
|
|
},
|
|
})
|
|
})
|
|
}(t, name, arch)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSRPM(t *testing.T) {
|
|
t.Parallel()
|
|
// The source package is architecture-independent (arch "src"); a single
|
|
// amd64 rebuild exercises the whole generate-spec → rpmbuild → install path.
|
|
t.Run("srpm/amd64/rebuild", func(t *testing.T) {
|
|
t.Parallel()
|
|
accept(t, acceptParms{
|
|
Name: "rebuild_amd64",
|
|
Conf: "srpm.rebuild.yaml",
|
|
Format: "srpm",
|
|
Docker: dockerParams{
|
|
File: "srpm.dockerfile",
|
|
Target: "rebuild",
|
|
Arch: "amd64",
|
|
},
|
|
})
|
|
})
|
|
}
|
|
|
|
func TestDebSpecific(t *testing.T) {
|
|
t.Parallel()
|
|
format := "deb"
|
|
testNames := []string{
|
|
"rules",
|
|
"triggers",
|
|
"breaks",
|
|
"predepends",
|
|
}
|
|
for _, name := range testNames {
|
|
for _, arch := range formatArchs[format] {
|
|
func(t *testing.T, testName, testArch string) {
|
|
t.Run(fmt.Sprintf("%s/%s/%s", format, testArch, testName), func(t *testing.T) {
|
|
t.Parallel()
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_%s", testName, testArch),
|
|
Conf: fmt.Sprintf("%s.%s.yaml", format, testName),
|
|
Format: format,
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("%s.dockerfile", format),
|
|
Target: testName,
|
|
Arch: testArch,
|
|
},
|
|
})
|
|
})
|
|
}(t, name, arch)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIPKSpecific(t *testing.T) {
|
|
t.Parallel()
|
|
format := "ipk"
|
|
testNames := []string{
|
|
"alternatives",
|
|
"conflicts",
|
|
"predepends",
|
|
}
|
|
for _, name := range testNames {
|
|
for _, arch := range formatArchs[format] {
|
|
func(t *testing.T, testName, testArch string) {
|
|
t.Run(fmt.Sprintf("%s/%s/%s", format, testArch, testName), func(t *testing.T) {
|
|
t.Parallel()
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_%s", testName, testArch),
|
|
Conf: fmt.Sprintf("%s.%s.yaml", format, testName),
|
|
Format: format,
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("%s.dockerfile", format),
|
|
Target: testName,
|
|
Arch: testArch,
|
|
},
|
|
})
|
|
})
|
|
}(t, name, arch)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRPMSign(t *testing.T) {
|
|
for _, os := range []string{
|
|
"centos9",
|
|
"centos10",
|
|
"fedora40",
|
|
"fedora41",
|
|
} {
|
|
os := os
|
|
t.Run(fmt.Sprintf("rpm/amd64/sign/%s", os), func(t *testing.T) {
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("sign_%s_amd64", os),
|
|
Conf: "core.signed.yaml",
|
|
Format: "rpm",
|
|
Docker: dockerParams{
|
|
File: fmt.Sprintf("rpm_%s.dockerfile", os),
|
|
Target: "signed",
|
|
Arch: "amd64",
|
|
},
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDebSign(t *testing.T) {
|
|
t.Parallel()
|
|
for _, arch := range formatArchs["deb"] {
|
|
for _, sigtype := range []string{"dpkg-sig", "debsign"} {
|
|
func(t *testing.T, testSigtype, testArch string) {
|
|
t.Run(fmt.Sprintf("deb/%s/%s", testArch, testSigtype), func(t *testing.T) {
|
|
t.Parallel()
|
|
target := "signed"
|
|
if testSigtype == "dpkg-sig" {
|
|
target = "dpkg-signed"
|
|
}
|
|
if testArch == "ppc64le" && os.Getenv("NO_TEST_PPC64LE") == "true" {
|
|
t.Skip("ppc64le arch not supported in pipeline")
|
|
}
|
|
accept(t, acceptParms{
|
|
Name: fmt.Sprintf("%s_sign_%s", testSigtype, testArch),
|
|
Conf: fmt.Sprintf("deb.%s.sign.yaml", testSigtype),
|
|
Format: "deb",
|
|
Docker: dockerParams{
|
|
File: "deb.dockerfile",
|
|
Target: target,
|
|
Arch: testArch,
|
|
},
|
|
})
|
|
})
|
|
}(t, sigtype, arch)
|
|
}
|
|
}
|
|
}
|
|
|
|
type acceptParms struct {
|
|
Name string
|
|
Conf string
|
|
Format string
|
|
Docker dockerParams
|
|
}
|
|
|
|
type dockerParams struct {
|
|
File string
|
|
Target string
|
|
Arch string
|
|
BuildArgs []string
|
|
}
|
|
|
|
func accept(t *testing.T, params acceptParms) {
|
|
t.Helper()
|
|
|
|
arch := strings.ReplaceAll(params.Docker.Arch, "armv", "arm/")
|
|
configFile := filepath.Join("./testdata/acceptance/", params.Conf)
|
|
tmp, err := filepath.Abs("./testdata/acceptance/tmp")
|
|
require.NoError(t, err)
|
|
packageName := params.Name + "." + params.Format
|
|
target := filepath.Join(tmp, packageName)
|
|
require.NoError(t, os.MkdirAll(tmp, 0o700))
|
|
|
|
envFunc := func(s string) string {
|
|
switch s {
|
|
case "BUILD_ARCH":
|
|
return strings.ReplaceAll(arch, "/", "")
|
|
case "SEMVER":
|
|
return "v1.0.0-0.1.b1+git.abcdefgh"
|
|
default:
|
|
return os.Getenv(s)
|
|
}
|
|
}
|
|
config, err := nfpm.ParseFileWithEnvMapping(configFile, envFunc)
|
|
require.NoError(t, err)
|
|
|
|
info, err := config.Get(params.Format)
|
|
require.NoError(t, err)
|
|
require.NoError(t, nfpm.Validate(info))
|
|
|
|
pkg, err := nfpm.Get(params.Format)
|
|
require.NoError(t, err)
|
|
|
|
cmdArgs := []string{
|
|
"build", "--rm", "--force-rm",
|
|
"--platform", fmt.Sprintf("linux/%s", arch),
|
|
"-f", params.Docker.File,
|
|
"--target", params.Docker.Target,
|
|
"--build-arg", "package=" + filepath.Join("tmp", packageName),
|
|
}
|
|
for _, arg := range params.Docker.BuildArgs {
|
|
cmdArgs = append(cmdArgs, "--build-arg", arg)
|
|
}
|
|
cmdArgs = append(cmdArgs, ".")
|
|
|
|
f, err := os.OpenFile(target, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o764)
|
|
require.NoError(t, err)
|
|
info.Target = target
|
|
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
|
|
//nolint:gosec
|
|
cmd := exec.Command("docker", cmdArgs...)
|
|
cmd.Dir = "./testdata/acceptance"
|
|
bts, err := cmd.CombinedOutput()
|
|
require.NoError(
|
|
t,
|
|
err,
|
|
"failed: %v; env BUILD_ARCH: %s; package: %s; output: %s",
|
|
cmd.Args,
|
|
envFunc("BUILD_ARCH"),
|
|
target,
|
|
string(bts),
|
|
)
|
|
}
|
|
|
|
func TestMSIXStructure(t *testing.T) {
|
|
t.Parallel()
|
|
for _, arch := range []string{"amd64", "arm64"} {
|
|
arch := arch
|
|
t.Run(arch, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
configFile := "./testdata/acceptance/msix.basic.yaml"
|
|
envFunc := func(s string) string {
|
|
switch s {
|
|
case "BUILD_ARCH":
|
|
return arch
|
|
case "SEMVER":
|
|
return "v1.0.0-0.1.b1+git.abcdefgh"
|
|
default:
|
|
return os.Getenv(s)
|
|
}
|
|
}
|
|
|
|
config, err := nfpm.ParseFileWithEnvMapping(configFile, envFunc)
|
|
require.NoError(t, err)
|
|
|
|
info, err := config.Get("msix")
|
|
require.NoError(t, err)
|
|
require.NoError(t, nfpm.Validate(info))
|
|
|
|
pkg, err := nfpm.Get("msix")
|
|
require.NoError(t, err)
|
|
|
|
var buf bytes.Buffer
|
|
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), &buf))
|
|
|
|
// Open the MSIX as a ZIP archive and verify structure
|
|
reader, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
|
|
require.NoError(t, err)
|
|
|
|
fileNames := make(map[string]bool)
|
|
for _, f := range reader.File {
|
|
fileNames[f.Name] = true
|
|
}
|
|
|
|
// Verify required MSIX structure files exist
|
|
require.True(t, fileNames["AppxManifest.xml"], "AppxManifest.xml must exist")
|
|
require.True(t, fileNames["AppxBlockMap.xml"], "AppxBlockMap.xml must exist")
|
|
require.True(t, fileNames["[Content_Types].xml"], "[Content_Types].xml must exist")
|
|
|
|
// Verify payload file exists
|
|
require.True(t, fileNames["app/fake.exe"], "payload file app/fake.exe must exist")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMSIStructure(t *testing.T) {
|
|
t.Parallel()
|
|
for _, arch := range []string{"amd64", "arm64"} {
|
|
arch := arch
|
|
t.Run(arch, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
configFile := "./testdata/acceptance/msi.basic.yaml"
|
|
envFunc := func(s string) string {
|
|
switch s {
|
|
case "BUILD_ARCH":
|
|
return arch
|
|
case "SEMVER":
|
|
return "v1.0.0-0.1.b1+git.abcdefgh"
|
|
default:
|
|
return os.Getenv(s)
|
|
}
|
|
}
|
|
|
|
config, err := nfpm.ParseFileWithEnvMapping(configFile, envFunc)
|
|
require.NoError(t, err)
|
|
|
|
info, err := config.Get("msi")
|
|
require.NoError(t, err)
|
|
require.NoError(t, nfpm.Validate(info))
|
|
|
|
pkg, err := nfpm.Get("msi")
|
|
require.NoError(t, err)
|
|
|
|
var buf bytes.Buffer
|
|
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), &buf))
|
|
|
|
// An MSI is an OLE Compound File (CFB) container.
|
|
cfbMagic := []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}
|
|
require.True(t, bytes.HasPrefix(buf.Bytes(), cfbMagic), "output must be a CFB container")
|
|
|
|
// The package must declare the platform it was built for rather
|
|
// than defaulting to x64.
|
|
platform := map[string]string{"amd64": "x64;", "arm64": "Arm64;"}[arch]
|
|
require.True(t, bytes.Contains(buf.Bytes(), []byte(platform)),
|
|
"package must declare the %q platform", platform)
|
|
|
|
// The package must pass ICE validation with no error-severity findings.
|
|
v, err := gomsi.NewValidator().WithAllICEs().Build()
|
|
require.NoError(t, err)
|
|
findings, err := v.Validate(bytes.NewReader(buf.Bytes()))
|
|
require.NoError(t, err)
|
|
for _, f := range findings {
|
|
if f.Severity() == gomsi.SeverityError {
|
|
t.Errorf("ICE error finding %s: %s", f.ICE(), f.Message())
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestMacOSStructure builds the three macOS formats from their acceptance
|
|
// configurations and reads each one back, for both architectures. The real
|
|
// installer, codesign and hdiutil check the same formats on a macOS runner;
|
|
// this is the structural check that runs anywhere.
|
|
func TestMacOSStructure(t *testing.T) {
|
|
t.Parallel()
|
|
for _, arch := range []string{"amd64", "arm64"} {
|
|
arch := arch
|
|
build := func(t *testing.T, format, configFile string) []byte {
|
|
t.Helper()
|
|
envFunc := func(s string) string {
|
|
switch s {
|
|
case "BUILD_ARCH":
|
|
return arch
|
|
case "SEMVER":
|
|
return "v1.0.0-0.1.b1+git.abcdefgh"
|
|
default:
|
|
return os.Getenv(s)
|
|
}
|
|
}
|
|
config, err := nfpm.ParseFileWithEnvMapping(configFile, envFunc)
|
|
require.NoError(t, err)
|
|
info, err := config.Get(format)
|
|
require.NoError(t, err)
|
|
require.NoError(t, nfpm.Validate(info))
|
|
packager, err := nfpm.Get(format)
|
|
require.NoError(t, err)
|
|
var buf bytes.Buffer
|
|
require.NoError(t, packager.Package(nfpm.WithDefaults(info), &buf))
|
|
return buf.Bytes()
|
|
}
|
|
macArch := map[string]string{"amd64": "x86_64", "arm64": "arm64"}[arch]
|
|
|
|
t.Run("pkg/"+arch, func(t *testing.T) {
|
|
t.Parallel()
|
|
raw := build(t, "pkg", "./testdata/acceptance/pkg.basic.yaml")
|
|
|
|
archive, err := osxpkg.Open(bytes.NewReader(raw), int64(len(raw)))
|
|
require.NoError(t, err)
|
|
// The container's checksums, and the payload against the bill of
|
|
// materials the installer keeps as its receipt.
|
|
require.NoError(t, archive.Verify())
|
|
require.True(t, archive.IsProduct(), "the package must be a product archive")
|
|
// The package must declare the architecture it was built for.
|
|
require.Equal(t, []string{macArch}, archive.HostArchitectures())
|
|
require.Equal(t, "11.0", archive.MinOSVersion())
|
|
require.Len(t, archive.Components(), 1)
|
|
component := archive.Components()[0]
|
|
require.NoError(t, component.Verify())
|
|
require.Equal(t, "dev.goreleaser.nfpm.basic", component.Identifier())
|
|
require.Equal(t, "1.0.0-0.1.b1+git.abcdefgh", component.Version())
|
|
|
|
payload, err := component.Payload()
|
|
require.NoError(t, err)
|
|
program, err := payload.Entry("/usr/local/bin/testapp")
|
|
require.NoError(t, err)
|
|
require.Equal(t, fs.FileMode(0o755), program.Mode())
|
|
link, err := payload.Entry("/usr/local/bin/testapp-link")
|
|
require.NoError(t, err)
|
|
require.Equal(t, "/usr/local/bin/testapp", link.LinkTarget())
|
|
_, err = payload.Entry("/private/etc/testapp/testapp.conf")
|
|
require.NoError(t, err, "/etc is stored as /private/etc")
|
|
_, err = component.PreInstallScript()
|
|
require.NoError(t, err)
|
|
_, err = component.PostInstallScript()
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Run("app/"+arch, func(t *testing.T) {
|
|
t.Parallel()
|
|
raw := build(t, "app", "./testdata/acceptance/app.basic.yaml")
|
|
|
|
archive, err := zip.NewReader(bytes.NewReader(raw), int64(len(raw)))
|
|
require.NoError(t, err)
|
|
modes := map[string]fs.FileMode{}
|
|
for _, f := range archive.File {
|
|
modes[f.Name] = f.Mode()
|
|
}
|
|
require.Contains(t, modes, "Test App.app/Contents/Info.plist")
|
|
require.Contains(t, modes, "Test App.app/Contents/PkgInfo")
|
|
require.Equal(t, fs.FileMode(0o755), modes["Test App.app/Contents/MacOS/testapp"],
|
|
"the main executable must stay executable")
|
|
require.Equal(t, fs.ModeSymlink, modes["Test App.app/Contents/Resources/launcher"].Type())
|
|
|
|
plist, err := fs.ReadFile(archive, "Test App.app/Contents/Info.plist")
|
|
require.NoError(t, err)
|
|
for _, want := range []string{
|
|
"<string>dev.goreleaser.nfpm.basic</string>",
|
|
"<string>1.0.0-0.1.b1+git.abcdefgh</string>",
|
|
"<key>LSUIElement</key>",
|
|
} {
|
|
require.Contains(t, string(plist), want)
|
|
}
|
|
})
|
|
|
|
t.Run("dmg/"+arch, func(t *testing.T) {
|
|
t.Parallel()
|
|
raw := build(t, "dmg", "./testdata/acceptance/app.basic.yaml")
|
|
|
|
image, err := osxdmg.Open(bytes.NewReader(raw), int64(len(raw)))
|
|
require.NoError(t, err)
|
|
// The checksums hdiutil verify checks.
|
|
require.NoError(t, image.Verify())
|
|
require.Equal(t, "Test App", image.VolumeName())
|
|
volume := image.FS()
|
|
info, err := fs.Stat(volume, "Test App.app/Contents/MacOS/testapp")
|
|
require.NoError(t, err)
|
|
require.Equal(t, fs.FileMode(0o755), info.Mode().Perm())
|
|
_, err = fs.Stat(volume, "Test App.app/Contents/Info.plist")
|
|
require.NoError(t, err)
|
|
links, ok := volume.(fs.ReadLinkFS)
|
|
require.True(t, ok)
|
|
target, err := links.ReadLink("Applications")
|
|
require.NoError(t, err)
|
|
require.Equal(t, "/Applications", target)
|
|
})
|
|
}
|
|
}
|