1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-05-27 08:56:17 +02:00
nfpm/deb/deb_test.go

146 lines
3.2 KiB
Go
Raw Normal View History

2018-01-04 13:31:22 +01:00
package deb
import (
2018-02-18 21:13:47 +01:00
"bytes"
"flag"
2018-02-25 21:29:31 +01:00
"fmt"
"io/ioutil"
2018-01-04 13:31:22 +01:00
"testing"
2018-02-05 02:53:22 +01:00
"github.com/goreleaser/nfpm"
2018-02-05 03:54:03 +01:00
"github.com/stretchr/testify/assert"
2018-01-04 13:31:22 +01:00
)
2018-02-18 21:13:47 +01:00
var update = flag.Bool("update", false, "update .golden files")
var info = nfpm.WithDefaults(nfpm.Info{
Name: "foo",
Arch: "amd64",
Depends: []string{
"bash",
},
Recommends: []string{
"git",
},
Suggests: []string{
"bash",
},
2018-02-18 21:13:47 +01:00
Replaces: []string{
"svn",
},
Provides: []string{
"bzr",
},
Conflicts: []string{
"zsh",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
2018-02-28 12:26:29 +01:00
Version: "v1.0.0",
2018-02-18 21:13:47 +01:00
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
2018-02-25 21:29:31 +01:00
"../testdata/fake": "/usr/local/bin/fake",
"../testdata/whatever.conf": "/usr/share/doc/fake/fake.txt",
2018-02-18 21:13:47 +01:00
},
ConfigFiles: map[string]string{
"../testdata/whatever.conf": "/etc/fake/fake.conf",
},
})
2018-01-04 13:31:22 +01:00
func TestDeb(t *testing.T) {
2018-02-18 21:13:47 +01:00
var err = Default.Package(info, ioutil.Discard)
assert.NoError(t, err)
}
func TestControl(t *testing.T) {
var w bytes.Buffer
assert.NoError(t, writeControl(&w, controlData{
Info: info,
InstalledSize: 10,
}))
var golden = "testdata/control.golden"
if *update {
ioutil.WriteFile(golden, w.Bytes(), 0655)
}
bts, err := ioutil.ReadFile(golden)
2018-01-04 13:31:22 +01:00
assert.NoError(t, err)
2018-02-18 21:13:47 +01:00
assert.Equal(t, string(bts), w.String())
2018-01-04 13:31:22 +01:00
}
2018-02-16 22:11:52 +01:00
func TestDebFileDoesNotExist(t *testing.T) {
var err = Default.Package(
nfpm.WithDefaults(nfpm.Info{
Name: "foo",
Arch: "amd64",
Depends: []string{
"bash",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
"../testdata/": "/usr/local/bin/fake",
},
ConfigFiles: map[string]string{
"../testdata/whatever.confzzz": "/etc/fake/fake.conf",
},
}),
ioutil.Discard,
)
assert.Error(t, err)
}
func TestDebNoFiles(t *testing.T) {
var err = Default.Package(
nfpm.WithDefaults(nfpm.Info{
Name: "foo",
Arch: "amd64",
Depends: []string{
"bash",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
}),
ioutil.Discard,
)
assert.NoError(t, err)
}
func TestDebNoInfo(t *testing.T) {
var err = Default.Package(nfpm.WithDefaults(nfpm.Info{}), ioutil.Discard)
assert.NoError(t, err)
}
func TestConffiles(t *testing.T) {
out := conffiles(nfpm.Info{
ConfigFiles: map[string]string{
"fake": "/etc/fake",
},
})
assert.Equal(t, "/etc/fake\n", string(out), "should have a trailing empty line")
}
func TestPathsToCreate(t *testing.T) {
2018-02-25 21:29:31 +01:00
for path, parts := range map[string][]string{
"/usr/share/doc/whatever/foo.md": []string{"usr", "usr/share", "usr/share/doc", "usr/share/doc/whatever"},
"/var/moises": []string{"var"},
"/": []string{},
} {
t.Run(fmt.Sprintf("path: '%s'", path), func(t *testing.T) {
assert.Equal(t, parts, pathsToCreate(path))
})
}
}