Skip to content

Commit

Permalink
fix: arch map for debian packages
Browse files Browse the repository at this point in the history
refs #21
  • Loading branch information
caarlos0 committed Mar 21, 2018
1 parent 9626479 commit 9f7e12a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 39 deletions.
14 changes: 14 additions & 0 deletions deb/deb.go
Expand Up @@ -24,6 +24,15 @@ func init() {
nfpm.Register("deb", Default)
}

var goarchToDebian = map[string]string{
"386": "i386",
"amd64": "amd64",
"arm": "armhf",
"arm64": "arm64",
"mips": "mips",
"mipsle": "mipsel",
}

// Default deb packager
var Default = &Deb{}

Expand All @@ -32,6 +41,11 @@ type Deb struct{}

// Package writes a new deb package to the given writer using the given info
func (*Deb) Package(info nfpm.Info, deb io.Writer) (err error) {
// TODO: add acceptance tests for this
arch, ok := goarchToDebian[info.Arch]
if ok {
info.Arch = arch
}
dataTarGz, md5sums, instSize, err := createDataTarGz(info)
if err != nil {
return err
Expand Down
86 changes: 47 additions & 39 deletions deb/deb_test.go
Expand Up @@ -13,52 +13,60 @@ import (

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",
},
Replaces: []string{
"svn",
},
Provides: []string{
"bzr",
},
Conflicts: []string{
"zsh",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "v1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
"../testdata/fake": "/usr/local/bin/fake",
"../testdata/whatever.conf": "/usr/share/doc/fake/fake.txt",
},
ConfigFiles: map[string]string{
"../testdata/whatever.conf": "/etc/fake/fake.conf",
},
})
func exampleInfo() nfpm.Info {
return nfpm.WithDefaults(nfpm.Info{
Name: "foo",
Arch: "amd64",
Depends: []string{
"bash",
},
Recommends: []string{
"git",
},
Suggests: []string{
"bash",
},
Replaces: []string{
"svn",
},
Provides: []string{
"bzr",
},
Conflicts: []string{
"zsh",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "v1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
"../testdata/fake": "/usr/local/bin/fake",
"../testdata/whatever.conf": "/usr/share/doc/fake/fake.txt",
},
ConfigFiles: map[string]string{
"../testdata/whatever.conf": "/etc/fake/fake.conf",
},
})
}

func TestDeb(t *testing.T) {
var err = Default.Package(info, ioutil.Discard)
assert.NoError(t, err)
for _, arch := range []string{"386", "amd64"} {
t.Run(arch, func(t *testing.T) {
info := exampleInfo()
info.Arch = arch
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,
Info: exampleInfo(),
InstalledSize: 10,
}))
var golden = "testdata/control.golden"
Expand Down
1 change: 1 addition & 0 deletions rpm/rpm.go
Expand Up @@ -32,6 +32,7 @@ type RPM struct{}

// Package writes a new RPM package to the given writer using the given info
func (*RPM) Package(info nfpm.Info, w io.Writer) error {
// TODO: add acceptance tests for this and test other archs
if info.Arch == "amd64" {
info.Arch = "x86_64"
}
Expand Down

0 comments on commit 9f7e12a

Please sign in to comment.