1
1
mirror of https://github.com/goreleaser/nfpm synced 2024-11-18 14:54:04 +01:00

test: added acceptance tests for overrides

This commit is contained in:
Carlos Alexandro Becker 2018-04-18 22:15:58 -03:00
parent 304cfa8a54
commit e8abe2ac61
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
6 changed files with 87 additions and 7 deletions

@ -1,14 +1,12 @@
package acceptance
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v1"
"github.com/goreleaser/nfpm"
// shut up
@ -17,7 +15,7 @@ import (
)
func accept(t *testing.T, name, conf, format, dockerfile string) {
var config = filepath.Join("./testdata", conf)
var configFile = filepath.Join("./testdata", conf)
tmp, err := filepath.Abs("./testdata/tmp")
require.NoError(t, err)
var packageName = name + "." + format
@ -25,11 +23,10 @@ func accept(t *testing.T, name, conf, format, dockerfile string) {
require.NoError(t, os.MkdirAll(tmp, 0700))
bts, err := ioutil.ReadFile(config)
config, err := nfpm.ParseFile(configFile)
require.NoError(t, err)
var info nfpm.Info
err = yaml.Unmarshal(bts, &info)
info, err := config.Get(format)
require.NoError(t, err)
require.NoError(t, nfpm.Validate(info))
@ -39,7 +36,7 @@ func accept(t *testing.T, name, conf, format, dockerfile string) {
f, err := os.Create(target)
require.NoError(t, err)
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), f))
bts, _ = exec.Command("pwd").CombinedOutput()
bts, _ := exec.Command("pwd").CombinedOutput()
t.Log(string(bts))
cmd := exec.Command(
"docker",

@ -20,6 +20,12 @@ func TestComplexDeb(t *testing.T) {
})
}
func TestComplexOverridesDeb(t *testing.T) {
t.Run("amd64", func(t *testing.T) {
accept(t, "overrides_deb", "overrides.yaml", "deb", "deb.overrides.dockerfile")
})
}
func TestMinDeb(t *testing.T) {
t.Run("amd64", func(t *testing.T) {
accept(t, "min_deb", "min.yaml", "deb", "deb.min.dockerfile")

@ -20,6 +20,12 @@ func TestComplexRPM(t *testing.T) {
})
}
func TestComplexOverridesRPM(t *testing.T) {
t.Run("amd64", func(t *testing.T) {
accept(t, "overrides_rpm", "overrides.yaml", "rpm", "rpm.overrides.dockerfile")
})
}
func TestMinRPM(t *testing.T) {
t.Run("amd64", func(t *testing.T) {
accept(t, "min_rpm", "min.yaml", "rpm", "rpm.min.dockerfile")

@ -0,0 +1,16 @@
FROM ubuntu
ARG package
COPY ${package} /tmp/foo.deb
RUN dpkg -i /tmp/foo.deb
RUN test -e /usr/local/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /tmp/preinstall-proof
RUN test -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN dpkg -r foo
RUN test -f /etc/foo/whatever.conf
RUN test ! -f /usr/local/bin/fake
RUN test -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof

33
acceptance/testdata/overrides.yaml vendored Normal file

@ -0,0 +1,33 @@
name: "foo"
arch: "amd64"
platform: "linux"
version: "v1.2.3-beta"
maintainer: "Foo Bar"
depends:
- bash
provides:
- fake
replaces:
- foo
suggests:
- zsh
description: |
Foo bar
Multiple lines
vendor: "foobar"
homepage: "https://foobar.org"
license: "MIT"
files:
../testdata/fake: "/usr/local/bin/fake"
./testdata/folder/**/*: "/usr/share/whatever/folder/"
config_files:
../testdata/whatever.conf: "/etc/foo/whatever.conf"
overrides:
rpm:
scripts:
preinstall: ./testdata/scripts/preinstall.sh
postremove: ./testdata/scripts/postremove.sh
deb:
scripts:
postinstall: ./testdata/scripts/postinstall.sh
preremove: ./testdata/scripts/preremove.sh

@ -0,0 +1,22 @@
FROM fedora
ARG package
COPY ${package} /tmp/foo.rpm
RUN rpm -ivh /tmp/foo.rpm
RUN test -e /usr/local/bin/fake
RUN test -f /etc/foo/whatever.conf
RUN test -d /usr/share/whatever/folder
RUN test -f /usr/share/whatever/folder/file1
RUN test -f /usr/share/whatever/folder/file2
RUN test -d /usr/share/whatever/folder/folder2
RUN test -f /usr/share/whatever/folder/folder2/file1
RUN test -f /usr/share/whatever/folder/folder2/file2
RUN test -f /tmp/preinstall-proof
RUN test ! -f /tmp/postinstall-proof
RUN test ! -f /tmp/preremove-proof
RUN test ! -f /tmp/postremove-proof
RUN echo wat >> /etc/foo/whatever.conf
RUN rpm -e foo
RUN test -f /etc/foo/whatever.conf.rpmsave
RUN test ! -f /usr/local/bin/fake
RUN test ! -f /tmp/preremove-proof
RUN test -f /tmp/postremove-proof