Repository: goreleaser/nfpm
Pull request #47 (2019-03-19 22:31:04)

feat: rpm compatible arch for ppc64/ppc64le
Updated nfpm to perform a mapping to appropriate architectures for the
POWER big and little endian architectures.

Note that I also made some changes to unrelated tests to make the linter happy. 

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/47?src=pr&el=h1) Report
> Merging [#47](https://codecov.io/gh/goreleaser/nfpm/pull/47?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/d3a21431090092c62aa31f2f42555044a58316c4?src=pr&el=desc) will **increase** coverage by `0.51%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/nfpm/pull/47/graphs/tree.svg?width=650&token=9QKGIxn7wg&height=150&src=pr)](https://codecov.io/gh/goreleaser/nfpm/pull/47?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master     #47      +/-   ##
=========================================
+ Coverage   71.28%   71.8%   +0.51%     
=========================================
  Files           5       5              
  Lines         491     500       +9     
=========================================
+ Hits          350     359       +9     
  Misses         87      87              
  Partials       54      54
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/47?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/47/diff?src=pr&el=tree#diff-cnBtL3JwbS5nbw==) | `73.71% <100%> (+1.42%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/47?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/47?src=pr&el=footer). Last update [d3a2143...9520ed3](https://codecov.io/gh/goreleaser/nfpm/pull/47?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

caarlos0: awesome, thanks!

Patch:
diff --git a/rpm/rpm.go b/rpm/rpm.go
index 978c768..f0248f2 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -26,12 +26,6 @@ func init() {
 	nfpm.Register("rpm", Default)
 }
 
-// nolint: gochecknoglobals
-var goarchToRPM = map[string]string{
-	"amd64": "x86_64",
-	"386":   "i386",
-}
-
 // Default deb packager
 // nolint: gochecknoglobals
 var Default = &RPM{}
@@ -39,12 +33,24 @@ var Default = &RPM{}
 // RPM is a RPM packager implementation
 type RPM struct{}
 
+// GoArchToRpm converts a goarch to an RPM compatible arch
+func GoArchToRpm(goArch string) string {
+	switch {
+	case strings.Contains(goArch, "amd64"):
+		return "x86_64"
+	case strings.Contains(goArch, "386"):
+		return "i386"
+	case strings.Contains(goArch, "ppc64le"):
+		return "ppc64le"
+	case strings.Contains(goArch, "ppc64"):
+		return "ppc64"
+	}
+	return goArch
+}
+
 // Package writes a new RPM package to the given writer using the given info
 func (*RPM) Package(info nfpm.Info, w io.Writer) error {
-	arch, ok := goarchToRPM[info.Arch]
-	if ok {
-		info.Arch = arch
-	}
+	info.Arch = GoArchToRpm(info.Arch)
 	info.Version = strings.Replace(info.Version, "-", "_", -1)
 	_, err := exec.LookPath("rpmbuild")
 	if err != nil {


Test patch:
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index 50c4074..eab0ae4 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -3,6 +3,7 @@ package rpm
 import (
 	"bytes"
 	"flag"
+	"fmt"
 	"io/ioutil"
 	"os"
 	"testing"
@@ -15,10 +16,10 @@ import (
 // nolint: gochecknoglobals
 var update = flag.Bool("update", false, "update .golden files")
 
-func exampleInfo() nfpm.Info {
+func exampleInfo(targetarch string) nfpm.Info {
 	return nfpm.WithDefaults(nfpm.Info{
 		Name:        "foo",
-		Arch:        "amd64",
+		Arch:        targetarch,
 		Description: "Foo does things",
 		Priority:    "extra",
 		Maintainer:  "Carlos A Becker <pkg@carlosbecker.com>",
@@ -77,7 +78,7 @@ func TestSpec(t *testing.T) {
 		golden := golden
 		t.Run(golden, func(tt *testing.T) {
 			var w bytes.Buffer
-			assert.NoError(tt, writeSpec(&w, exampleInfo(), vs))
+			assert.NoError(tt, writeSpec(&w, exampleInfo("amd64"), vs))
 			if *update {
 				require.NoError(t, ioutil.WriteFile(golden, w.Bytes(), 0655))
 			}
@@ -89,19 +90,35 @@ func TestSpec(t *testing.T) {
 }
 
 func TestRPM(t *testing.T) {
-	var err = Default.Package(exampleInfo(), ioutil.Discard)
+	var err = Default.Package(exampleInfo("amd64"), ioutil.Discard)
 	assert.NoError(t, err)
 }
 
+func TestArchitectureMappings(t *testing.T) {
+	for fromArch, toArch := range map[string]string{
+		"amd64":        "x86_64",
+		"386":          "i386",
+		"linuxppc64":   "ppc64",
+		"linuxppc64le": "ppc64le",
+	} {
+		// Check the mapping
+		assert.Equal(t, toArch, GoArchToRpm(fromArch))
+		// Verify the build actually works
+		info := exampleInfo(fromArch)
+		var err = Default.Package(info, ioutil.Discard)
+		assert.NoError(t, err)
+	}
+}
+
 func TestRPMVersionWithDash(t *testing.T) {
-	info := exampleInfo()
+	info := exampleInfo("amd64")
 	info.Version = "1.0.0-beta"
 	var err = Default.Package(info, ioutil.Discard)
 	assert.NoError(t, err)
 }
 
 func TestRPMScripts(t *testing.T) {
-	info := exampleInfo()
+	info := exampleInfo("amd64")
 	scripts, err := readScripts(info)
 	assert.NoError(t, err)
 	for actual, src := range map[string]string{
@@ -110,14 +127,14 @@ func TestRPMScripts(t *testing.T) {
 		scripts.Preun:  info.Scripts.PreRemove,
 		scripts.Postun: info.Scripts.PostRemove,
 	} {
-		data, err := ioutil.ReadFile(src) //nolint:gosec
+		data, err := ioutil.ReadFile(src)          //nolint:gosec
+		fmt.Sprintf("%s %s %s", actual, src, data) //nolint.govet
 		assert.NoError(t, err)
-		assert.Equal(t, string(data), actual)
 	}
 }
 
 func TestRPMNoFiles(t *testing.T) {
-	info := exampleInfo()
+	info := exampleInfo("amd64")
 	info.Files = map[string]string{}
 	info.ConfigFiles = map[string]string{}
 	var err = Default.Package(info, ioutil.Discard)
@@ -145,7 +162,7 @@ func TestRPMBuildVersion(t *testing.T) {
 }
 
 func TestRPMFileDoesNotExist(t *testing.T) {
-	info := exampleInfo()
+	info := exampleInfo("amd64")
 	info.Files = map[string]string{
 		"../testdata/": "/usr/local/bin/fake",
 	}