Skip to content

Commit

Permalink
test: added some more
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Feb 16, 2018
1 parent 00335c9 commit e5fe548
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
5 changes: 4 additions & 1 deletion deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func createDataTarGz(now time.Time, info nfpm.Info) (dataTarGz, md5sums []byte,
defer compress.Close() // nolint: errcheck

var md5buf bytes.Buffer
for _, files := range []map[string]string{info.Files, info.ConfigFiles} {
for _, files := range []map[string]string{
info.Files,
info.ConfigFiles,
} {
for src, dst := range files {
size, err := copyToTarAndDigest(out, &md5buf, now, src, dst)
if err != nil {
Expand Down
57 changes: 56 additions & 1 deletion deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,66 @@ func TestDeb(t *testing.T) {
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
"../testdata/fake": "/usr/local/bin/fake",
"../testdata/fake": "/usr/local/bin/fake",
},
ConfigFiles: map[string]string{
"../testdata/whatever.conf": "/etc/fake/fake.conf",
},
}),
ioutil.Discard,
)
assert.NoError(t, err)
}

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 <[email protected]>",
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 <[email protected]>",
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)
}
25 changes: 25 additions & 0 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,28 @@ func TestRPM(t *testing.T) {
)
assert.NoError(t, err)
}

func TestNoFiles(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 <[email protected]>",
Version: "1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
License: "MIT",
Bindir: "/usr/local/bin",
Files: map[string]string{},
ConfigFiles: map[string]string{},
}),
ioutil.Discard,
)
assert.Error(t, err)
}

0 comments on commit e5fe548

Please sign in to comment.